Leetcode.md (6890B)
1 @title: Leetcode, an honest review 2 @date: 2025-01-01 3 @language: en 4 @categories: general, leetcode 5 6 # Leetcode an honest review 7 8 ## Overview 9 10 My [leetcode journey](https://leetcode.com/u/dimitrijed/) has started on Nov 5, 2022 as a way to prepare for 11 algorithms class. As I've done more and more problems it slowly turned into an 12 obsession. I was doing problem after problem, from many different categories. 13 For the duration of 2023 and 2024, every single day, I've been doing at least 14 one problem - a Daily problem if it hasn't already been solved, or a random 15 problem if it has. Usually, that was all I did, but when I was bored, I 16 would do 5, 10 or even 20 problems. 17 18 The summary is as follows (at the time of writing): 19 * Streak: 737/789 days 20 * Rank: 3,601/~5mil people 21 * Easy: 350/846 problems 22 * Medium: 968/1775 problems 23 * Hard: 182/785 problems 24 * Total: 1500 problems 25 * Badges: 44 26 27 28 ## Routine 29 30 During the day, when I found the time, I sat down ready to tackle one 31 problem. I would do my best to solve it without looking at hints and solutions. 32 Goal was to find the best possible algorithm, which in practice means beating 33 85% submissions or more. Based on the problem, this would take anywhere between 34 5 and 20 minutes, and then I would try to utilize a hint, in case there was 35 something I'd missed. 36 37 If that didn't help, I would turn to the official or community solution, in 38 order to understand what I'd missed and how exactly does the algorithm need to 39 work, then I would try to implement it myself, often more clearly and 40 concisely. Even if I've managed to solve a problem in the satisfactory 41 complexity, I would still take a look at the solutions just to see whether 42 there is something worth remembering. I've picked up a lot of great trick 43 this way. 44 45 46 ## Learning 47 48 Because of my competitive programming background from middle school and high 49 school, I was already quite familiar with the format as well as logical 50 thinking, which has kick-started the beginning. 51 52 At that time, I've been writing a lot of C, but I wanted to get good at C++. 53 I'd seen STL before, but I lacked deep understanding of it all. I've started 54 with some introductory problems, that mostly tested logic, but soon enough I 55 started dabbling with more advanced topics like Trees and Graphs. That is where 56 the real fun began. I was aware of the few algorithms from the class, but when 57 it came time to actually implement them I was thunder struck. It was a crucial 58 step at the time to take a look at other people's solutions and see how exactly 59 are the data structures represented in C++ code, and how to interact with them. 60 61 As my knowledge of algorithms grew, so did my understanding of C++, although 62 I've spent an additional time learning about it's inner workings. It came to 63 the point where language was not an issue anymore. That's when I've started 64 thinking beyond the problem at hand, and more about the codding style, as 65 well as the best utilization of processor and memory. 66 67 68 ## Problems 69 70 There are many different kinds of problems, regardless of their difficulty: 71 * Brain testers - usually math related and require logical thinking 72 * Strictly math problems - based on advanced math knowledge 73 * Little problems - not necessarily hard, but can be tricky to implement elegantly 74 * Straight foreword problems - one you've seen the underlying idea, they are 75 not that difficult 76 * Problems that require a well-known algorithm in order to be solved. I don't 77 think any mortal can come up with them in any reasonable amount of time. 78 79 Most of the problems require a specific technique to be solved, such as sliding 80 window, two pointer, binary search... The more problems you do, the easier it 81 will be to spot these patterns quickly, and implement the adequate solution. 82 The issue may arise, when a few of these techniques are required simultaneously. 83 84 85 ## Difficulty. 86 87 Easy problems are easy mainly because of the restrictions. Any valid solution, 88 regardless of the complexity, will work. Most of them are trivial, but there 89 are a few hidden gems that serve as an introduction to a well-known algorithms 90 to be used in harder problems. This is a good reason to look at other solutions 91 even if running time is satisfactory - inefficiency is masked by small constants. 92 93 Medium problems vary drastically. There are some trivial ones, some that are 94 just tedious to code, some that require solid understanding of common 95 algorithms and data structures, while some require specific algorithm that is 96 worth remembering. Due to the wide array of possibilities, there are some 97 medium problems that I've solved in under a minute, while even after I've done 98 so many of them, from time to time, I come across one that I have no idea where 99 to even start. This is a fact of life, and there is no point in beating your 100 head about it. 101 102 Hard problems are weird. There are some that require ultra specific algorithms, 103 some that require outstanding out the box thinking, while still being possible 104 to come up with. My favorite ones are those that require perfect 105 understanding of the common algorithms and data structures, then adding some 106 twist to it, whether it's a combination or transformation that is needed in 107 order for it to work. Some are just impossible to understand, even with a 108 solution... 109 110 111 ## Advice 112 113 Doing 1500 problems is really unnecessary if your main focus are interviews. 114 Focusing on [neetcode](https://neetcode.io/) will be enough for most people. 115 116 117 There are a few things worth remembering: 118 119 * Code, Code, Code! Every single solution needs to be actually coded, 120 tested and run. There are no too easy problems. Everything counts. 121 * You need to be aware of your weaknesses, whether it's the understanding 122 of the language that is holding you back, or it's some algorithm or a 123 data structure. 124 * Once you've learned a new concept, you should drill it until it becomes 125 second nature. There should be no rush between problems, unless everything 126 is crystal clear. Otherwise you will waste a lot of time reviewing concepts 127 that should have been mastered a long time ago. 128 * Not everything is in the algorithms and data structures. Clean and concise 129 code also matters a lot 130 * Copying the solution to the paper by hand really helps internalize the ideas. 131 Do this only for a small number of special problems, as not to waste too much 132 time. 133 134 135 ## Conclusion 136 137 I'll be taking a break, possibly forever, form leetcode. It's been fun, but 138 I've passed the point of diminishing returns for where I want to be, so it's 139 better for me to focus my energy elsewhere. The lesions I've learned will 140 continue to serve me in the future, both the algorithms and data structures, as 141 well as the logic and general practice of coding. 142 143 I haven't given competitions an honest shot, mostly due to the incontinent time 144 at which they are held. Although, they might be a new step forward, to keep me 145 from getting rusty.