All free guides

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

Start here

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.

1 · Arrays and hashing 2 · Two pointers and sliding window 3 · Binary search 4 · Stacks and queues 5 · Trees and graphs 6 · Dynamic programming
  • 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.
The method

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–5
217Contains DuplicateEASY

Given 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.

Hash set · O(n) time, O(n) space
242Valid AnagramEASY

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.

Frequency map · O(n) time
1Two SumEASY

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.

Hash map · O(n) time
49Group AnagramsMEDIUM

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.

Map to a list · O(n · k log k), k = word length
347Top K Frequent ElementsMEDIUM

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.

Counting and buckets · O(n) time

Two pointers, sliding window

BLOCK 2 · 6–10
125Valid PalindromeEASY

Ignoring 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.

Two pointers · O(n) time, O(1) space
167Two Sum II — Input Array Is SortedMEDIUM

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.

Two pointers · O(n) time, O(1) space
153SumMEDIUM

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.

Sort and two pointers · O(n²) time
3Longest Substring Without Repeating CharactersMEDIUM

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.

Sliding window · O(n) time
424Longest Repeating Character ReplacementMEDIUM

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.

Window with counts · O(n) time

Stacks and queues

BLOCK 4 · 16–20
20Valid ParenthesesEASY

Are 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.

Stack · O(n) time
232Implement Queue using StacksEASY

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.

Two stacks · O(1) amortised per operation
155Min StackMEDIUM

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.

Stack of pairs · O(1) per operation
739Daily TemperaturesMEDIUM

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.

Monotonic stack · O(n) time
84Largest Rectangle in HistogramHARD

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.

Monotonic stack · O(n) time

Trees and graphs

BLOCK 5 · 21–25
104Maximum Depth of Binary TreeEASY

How 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.

Tree DFS · O(n) time
226Invert Binary TreeEASY

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.

Tree DFS · O(n) time
102Binary Tree Level Order TraversalMEDIUM

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.

BFS with a queue · O(n) time
98Validate Binary Search TreeMEDIUM

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.

DFS with bounds · O(n) time
200Number of IslandsMEDIUM

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.

Grid DFS or BFS · O(m · n) time

Dynamic programming

BLOCK 6 · 26–30
70Climbing StairsEASY

How 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.

1-D DP · O(n) time, O(1) space
746Min Cost Climbing StairsEASY

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.

1-D DP · O(n) time, O(1) space
198House RobberMEDIUM

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".

1-D DP with a skip · O(n) time, O(1) space
53Maximum SubarrayMEDIUM

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?

Kadane · O(n) time, O(1) space
322Coin ChangeMEDIUM

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.

Unbounded DP · O(amount × coins) time
Four weeks

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.

Week 1Arrays, hashing, first two pointers
Mon–Tue217 Contains Duplicate · 242 Valid Anagram · 1 Two Sum
Wed–Thu49 Group Anagrams · 347 Top K Frequent Elements
Fri–Sat125 Valid Palindrome · 167 Two Sum II · 15 3Sum
SundayRest. Nothing. Close the laptop.
Week 2Sliding window and binary search
Mon–Tue3 Longest Substring · 424 Character Replacement
Wed–Thu704 Binary Search · 74 Search a 2D Matrix
Fri–Sat153 Find Minimum · 33 Search Rotated · 875 Koko
SundayRest, then redo any one problem from week 1 from scratch.
Week 3Stacks, queues, first trees
Mon–Tue20 Valid Parentheses · 232 Queue using Stacks · 155 Min Stack
Wed–Thu739 Daily Temperatures · 84 Largest Rectangle
Fri–Sat104 Maximum Depth · 226 Invert Tree · 102 Level Order
SundayRest. Week 3 is where people quit; do not.
Week 4Graphs and dynamic programming
Mon–Tue98 Validate BST · 200 Number of Islands
Wed–Thu70 Climbing Stairs · 746 Min Cost Stairs · 198 House Robber
Fri–Sat53 Maximum Subarray · 322 Coin Change
SundayRedo the five that hurt the most. No notes.
Ninety minutes, three questions

In 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.

Top 30 DSA Problems for Placement Interviews