Pass the coding test
Top 30 LeetCode Problems for Freshers, In Order
Riya had solved 34 problems before her first campus test. Aarav had solved 180. Riya cleared two of the three questions. Aarav cleared one. The difference was not effort. Riya solved hers in an order , so the window question in the test looked like something she had met before. Aarav's 180 were random, so every question was new.
12 min readFree, no email neededUpdated 11 September 2026
Why thirty, and why this order
Riya had solved 34 problems before her first campus test. Aarav had solved 180. Riya cleared two of the three questions. Aarav cleared one. The difference was not effort. Riya solved hers in an order, so the window question in the test looked like something she had met before. Aarav's 180 were random, so every question was new.
A fresher coding test is not a memory test. It is a pattern-recognition test. Almost every question you will get is one of six ideas in a costume. Solve these thirty, in this order, and you will recognise the costume.
- Every problem uses something from the one before itTwo Sum teaches the hash map. Group Anagrams uses the hash map on a harder key. 3Sum reuses the two-pointer idea you just learnt on Two Sum II. Solve them out of order and you lose that.
- This is a map, not a solutions manualYou get the statement, the key insight in one sentence, and the complexity to aim for. The code is yours to write. That is the part the test grades.
How to use this list
The 20-minute rule. Set a timer. Think for twenty minutes with nothing open but the problem. No editorial, no video, no AI. If you have an approach at twenty minutes, keep going as long as you are making progress.
If you are stuck at twenty minutes, read one paragraph. Open the editorial or the top discussion post and read only until you get the idea — usually the first paragraph. Then close it and write the code yourself. Copying the code teaches you nothing; getting one nudge and finishing it teaches you the pattern.
Write the complexity down before you submit. Time and space, on paper, in your own words. Compare it with the target in this guide. If yours is worse, you have solved a different problem than the one they asked.
Redo it three days later. Any problem you needed help on, do again from scratch three days later, with no notes. Three days is roughly when a borrowed idea falls out of your head. If you cannot do it clean, redo it three days after that.
Type it, do not read it. Reading a solution feels like learning and is not. Your hands need to have typed the two-pointer loop about five times before it comes out under pressure.
Honest pace. Two problems a day, six days a week. Thirty problems takes about four weeks. Doing eight in one Sunday and none for a fortnight does not work — spacing is the whole point.
Arrays and hashing
BLOCK 1 · 1–5Given a list of numbers, say whether any number appears more than once.
Insight: a set answers "have I seen this before?" in one step, so a single pass is enough.
Do two words use exactly the same letters, the same number of times?
Insight: count the letters in both words and compare the two counts; order stops mattering.
Find the two positions whose values add up to a given target.
Insight: as you walk the list, look up "target minus this number" in a map of everything you have already passed.
Put words that are anagrams of each other into the same group.
Insight: anagrams share a key — the word with its letters sorted — so use that key in a map from key to list.
Return the k numbers that appear most often in the list.
Insight: count first, then place each number in a bucket indexed by its count and read the buckets from the top; no sorting needed.
Two pointers, sliding window
BLOCK 2 · 6–10Ignoring spaces, punctuation and case, does the string read the same both ways?
Insight: one pointer from each end walking inward, each skipping anything that is not a letter or digit.
The same task as Two Sum, except the array is already sorted.
Insight: sorted means you can steer. If the pair sums too high, pull the right pointer in; too low, push the left one out.
Find every group of three numbers that adds up to zero, with no repeated group.
Insight: sort, fix the first number, then run problem 167 on the rest; skipping over equal neighbours is what removes the duplicates.
How long is the longest stretch of the string with no character repeated?
Insight: grow the window on the right; when a character repeats, drag the left edge past where that character last appeared.
You may change up to k characters. How long a stretch of one repeated letter can you make?
Insight: a window is legal when its length minus the count of its most common letter is at most k; shrink from the left when it is not.
Binary search
BLOCK 3 · 11–15Find a value in a sorted array, or report that it is not there.
Insight: get the template exactly right once — while lo <= hi and mid = lo + (hi - lo) // 2 — and never improvise it again.
Search a matrix whose rows are sorted and where each row begins after the previous one ends.
Insight: it is one sorted list of length m × n wearing a costume; convert the index back to a row and column with divide and remainder.
A sorted array was rotated by some amount. Find its smallest value.
Insight: compare the middle with the right end; that one comparison tells you which half still contains the rotation point.
The same rotated array, but now find a given value in it.
Insight: after any split, one half is always properly sorted; check whether the target sits inside that half, and if not, go to the other.
Choose the smallest eating speed that still finishes every pile within h hours.
Insight: you are not searching an array, you are searching the range of possible answers. Write a "can she finish at this speed?" check and binary search on it.
Stacks and queues
BLOCK 4 · 16–20Are the brackets in the string opened and closed in the right order?
Insight: push every opening bracket; a closing bracket must match whatever is on top, and the stack must end empty.
Build a working queue when the only tool you are given is stacks.
Insight: two stacks. Push into one, pop from the other, and move everything across only when the output stack runs empty.
A stack that can also tell you its smallest value at any moment.
Insight: store the minimum-so-far next to each value you push, so popping restores the old minimum for free.
For each day, how many days until a warmer day arrives?
Insight: keep a stack of days still waiting for something warmer; one warm day pops and answers several of them at once.
Find the biggest rectangle that fits under a row of bars of different heights.
Insight: the same waiting stack as problem 739 — when a shorter bar arrives, every taller bar on the stack has just found its right edge. This one is the stretch; give it thirty minutes, then read.
Trees and graphs
BLOCK 5 · 21–25How many levels deep does the tree go?
Insight: the depth of a node is one plus the deeper of its two children. That sentence is the entire solution.
Mirror the whole tree left to right.
Insight: swap the two children at every node and let the recursion handle the rest of the tree.
Return the node values one level at a time, top to bottom.
Insight: take the queue's size before the inner loop starts; that number is exactly one level's worth of nodes.
Is every node sitting in a legal position for a binary search tree?
Insight: comparing a node only with its parent is the trap. Carry a low and a high bound down to every node and check against those.
Count the separate blocks of land in a grid made of land and water.
Insight: scan for land, and when you find some, sink the entire island you are standing on so it can never be counted twice.
Dynamic programming
BLOCK 6 · 26–30How many ways are there to climb n steps, taking one or two at a time?
Insight: the ways to reach step i are the ways to reach i-1 plus the ways to reach i-2. It is Fibonacci in a costume.
The same stairs, but standing on a step costs money. Find the cheapest way up.
Insight: the same recurrence as problem 70, except you take the cheaper of the two choices instead of adding them together.
Take the largest total from a row of houses without taking two that are next to each other.
Insight: at every house the best answer is either "skip it, keep the previous best" or "take it, plus the best from two houses back".
Find the run of consecutive numbers with the largest sum.
Insight: at every position ask one question — is the running sum still helping me, or should I start fresh from here?
The fewest coins that add up to a given amount, or -1 if it cannot be done.
Insight: build the answer for every amount from 1 upward; the answer for x is one plus the best of x minus each coin.
The schedule
Two problems on a working day, one rest day a week. Numbers below are LeetCode numbers, in the order given in this guide.
217 Contains Duplicate · 242 Valid Anagram · 1 Two Sum49 Group Anagrams · 347 Top K Frequent Elements125 Valid Palindrome · 167 Two Sum II · 15 3Sum3 Longest Substring · 424 Character Replacement704 Binary Search · 74 Search a 2D Matrix153 Find Minimum · 33 Search Rotated · 875 Koko20 Valid Parentheses · 232 Queue using Stacks · 155 Min Stack739 Daily Temperatures · 84 Largest Rectangle104 Maximum Depth · 226 Invert Tree · 102 Level Order98 Validate BST · 200 Number of Islands70 Climbing Stairs · 746 Min Cost Stairs · 198 House Robber53 Maximum Subarray · 322 Coin ChangeIn the test itself
Read all the questions first. Two minutes, no code. Then start with the one that looks easiest. The marks are the same whichever order you solve them in, and the confidence from an early solve is worth more than the two minutes.
Check the constraints before you choose an approach. If n is at most 1,000 then an O(n²) loop is fine and you should just write it. If n can be 100,000 then O(n²) will time out and you need the pattern. The constraints are the hint.
Brute force first, then optimise. A submitted O(n²) that passes most cases beats an elegant O(n) you never finished. Get something working, save it, then improve it.
Never delete a working solution to try a faster one. Copy it into a comment at the bottom of the file first. If the clever version does not come together in ten minutes, paste the old one back.
When a hidden case fails, print the input. Most hidden failures are the same four things: an empty array, a single element, all values equal, and negative numbers. Test those four by hand before you submit anything.
Watch the clock out loud. Fifteen minutes left and question three untouched means you stop polishing question two and go write the brute force for three.
Want this on your phone?
Everything above, as a PDF built to read on a phone the morning of the interview. It costs nothing — we ask for an email so we can send it, and that is all.