Leetcode
Chester Wyke March 24, 2025 Updated: April 27, 2025 #MiscI quite enjoy doing leetcode as small contained puzzles that are easy to verify. It’s also pretty good for trying out a new language in some regards. This page is a collection of resources for various purposes:
Problem solving tips and notes
This is a list of tips I want to remember. It’s likely that there is a more comprehensive list somewhere but I haven’t looked for it. There are just small techniques to apply. Not really a full pattern but just a way to reframe problems. If you know of a comprehensive list of techniques like these please tell me about it. I’ll check it out and link to it if I find it good. I included an example problem where the technique applies.
Try brute force
Coding up brute force is a good starting point but a better starting point is just typing out or writing up what you need to keep track of to solve it as a human. Add “digital” constraints like only looking at one variable at a time and then try to solve and see where you have repeated work and things like that which could cause the optimal solution to fall out. In the example problem once I looked at Deepti manually solve it, the solution became obvious and I wasn’t stuck anymore.
Rearrange formulas (especially if modulus is involved - think of operations closed under modulus (+,-,*))
Source: Taken from Hint #2 for problem.
Check to see if formulas in question can be rearranged into one that is easier to optimize for
Notice that (j - i != nums[j] - nums[i]) is the same as (nums[i] - i != nums[j] - j).
Consider partition_point
Inspired by: https://www.youtube.com/watch?v=TjthKf7Mc_8
- 33. Search in Rotated Sorted Array
- 34. Find First and Last Position of Element in Sorted Array
- 704. Binary Search
When you need binary search consider using partition_point
function from rust std. If it’s not allowed manually implement as below.
/// Returns the index of the partition point according to the given predicate (the index of the first element of the second partition).
/// See <https://doc.rust-lang.org/std/primitive.slice.html#method.partition_point> for more info
Be comfortable with permutations
Sometimes brute force is what the question wants. I prefer Heap’s Algorithm but it’s too difficult to memorize. So instead I think the iterative solution from the video is the easiest to remember without feeling too icky
/// Based on https://www.youtube.com/watch?v=FZe0UqISmUw
Be comfortable with subsets
Note that this is not subarrays. Similarly to permutations an iterative approach can be used to just add all numbers to the end only instead of all positions like permutations.
Interview Preparation
In my opinion if you already have experience with leetcode then a good video to start with is this one from Uncle Steve where he starts of with summarizing the article How well do LeetCode ratings predict interview performance? Here’s the data.
List of leetcode problems from the description of the video:
Top ‘Secretly Easy’ Hard Problems:
#1: Reverse Nodes in k-Group - Score: 0.034
#2: Median of Two Sorted Arrays - Score: 0.0298
#3: N-Queens II - Score: 0.0288
#4: N-Queens - Score: 0.0255
#5: Robot Room Cleaner - Score: 0.0192Top ‘Most Efficient for Interview Prep’ Hard Problems:
#1: Longest Increasing Path in a Matrix - Score: 1.8094
#2: Trapping Rain Water - Score: 1.6964
#3: The Skyline Problem - Score: 1.5794
#4: Word Break II - Score: 1.5601
#5: Smallest Range Covering Elements from K Lists - Score: 1.1687Hardest Questions Actually Used in FAANG Interviews:
#1: Partition Array Into Two Arrays to Minimize Sum Difference - Score: 12.3924
#2: Regular Expression Matching - Score: 12.1070
#3: Reverse Pairs - Score: 9.0915
#4: Median of Two Sorted Arrays - Score: 8.2952
#5: Max Points on a Line - Score: 8.0952
If you’re new to leetcode then start with neetcode it makes it easy to find a path to follow. My key takeaway is that “reasonable” hard problems are actually not hard just require multiple techniques and thus you get more value from doing them. But be warned some of them just require niche knowledge. The following are some lists I think are worth taking a look at and why. When starting off getting practice on types of solutions is good to help you build up intuition on when a type of solution is appropriate. However, once you are comfortable with the solution types at least in general then not having a hint on what type of solution to use is better to help you identify what type of solution you should use instead of being suggested one.
These are some good videos to help you get oriented:
List | Reason | Organization |
---|---|---|
NeetCode Roadmap | Provides a guided tree to follow based on prerequisites | Tree with solution types |
LeetCode 75 | Provided by leetcode and free (they also have list available to premium users, support them if you’re able) | Grouped by Solution Type |
AlgoMaster | Has links to an explanation for each solution type before the problems. Has links to solutions for each problem (seems like his) and preloaded search for solutions on YouTube | Grouped by Solution Type |
Grind 75 by author of Blind 75 | Allows customization of plan to the amount of time you have available and can not show what topic is covered by a question for you to practice that skill | Customizable |
Recreational
If you’re objective is just practice or for fun then working locally can be less annoying than working in the text editor provided. Also if you want to get practice with using your IDE of choice and learning from the autocomplete and docs displayed in the IDE. Then I recommend cargo-leet. It’s a pretty basic download tool that just tries to setup the tests from the description for you. Happy to accept contributions if you’re so included.