Start here: LeetCode from zero
New to coding? This page is for you. You do not need to know any algorithms yet. Read it once (about 15 minutes), then do your first problem.
- Make a free LeetCode account and pick Go as the language.
- Read Go for Interviews once.
- Solve Contains Duplicate using the steps in section 4.
- Write two sentences in a notebook: what was the trick?
Can I start?
You only need the basics of any one language: variables, if statements, loops and functions. If those words are new, spend a week on a free beginner course first (for example the Tour of Go), then come back. That is completely fine.
Words you will see
- Array / slice:
- A numbered list of values, like [4, 7, 9]. In Go it is called a slice.
- Hash map:
- A lookup table. You give it a key (a name) and it gives back a value instantly.
- Hash set:
- Like a hash map, but it only remembers which keys it has seen.
- Big-O:
- A way to say how slow code gets when the input grows. O(n) means “one step per item”.
- O(n²):
- Two loops inside each other. Fine for 100 items, too slow for 100,000.
- Recursion:
- A function that calls itself on a smaller version of the same problem.
- Brute force:
- The simple, slow idea that tries everything. A good first step.
- Edge case:
- A strange input, like an empty list or one item, that can break your code.
The big idea
LeetCode is a website with coding puzzles. Companies use the same kind of puzzle in job interviews. Most people practise in a way that feels busy but does not work: they read answers and move on. Studies of how people learn, and advice from many experienced coders, agree on three simple rules:
- Learn patterns, not answers. A pattern is a trick that fits many problems. A small set of them covers most problems.
- Try first, then get small hints. Struggling for a short time is what makes the idea stick. Struggling for hours does not.
- Redo problems later. You remember what you recall again after a gap, not what you only re-read.
1. What a problem is
Every problem gives you a function signature, a few examples and some constraints. Your job is to write the function body so that it returns the right output for every valid input and runs fast enough. Take Contains Duplicate: given a list of numbers, return true if any number appears twice.
func containsDuplicate(nums []int) bool {
// your code here
}2. Set up in 5 minutes
- Make a free LeetCode account. In the editor, choose Go as the language. The editor runs your code against the tests.
- Optional but recommended: install Go so you can run code offline, or use the Go Playground in the browser.
- Read Go for Interviews once. It is short and covers slices, maps and the gotchas that waste beginners' time.
3. Read the constraints first
The size limit tells you which speed you are aiming for before you think of any idea. If a list can hold 100,000 numbers, an approach that compares every pair (about 10 billion steps) will time out. Look at the largest n in the constraints:
| If n is… | Aim for | Typical tools |
|---|---|---|
| n ≤ 10 | O(n!) | Try every ordering: permutations, backtracking. |
| n ≤ 20 | O(2ⁿ) | Try every subset: backtracking, bitmasks. |
| n ≤ 500 | O(n³) | Three nested loops are fine; interval DP lives here. |
| n ≤ 5,000 | O(n²) | A DP table or two nested loops. |
| n ≤ 100,000 | O(n log n) | Sort first, use a heap, or binary search. |
| n ≥ 1,000,000 | O(n) or O(log n) | One pass: hash map, two pointers, sliding window, math. |
New to this notation? The Big-O cheat sheet explains it with pictures.
4. Your first problem, step by step
Use the same five moves on every problem. Here they are on Contains Duplicate:
- Say it in your own words. “Is any number in the list repeated?”
- Work a tiny example by hand.
[1, 2, 3, 1]→ yes, 1 appears twice.[1, 2, 3]→ no. - Write the slow idea first. Compare every pair: two nested loops, O(n²). It is correct, and saying it out loud is a legitimate first step in an interview.
- Ask what is being repeated. The inner loop keeps asking “have I seen this number before?”. A hash set answers that in O(1), so keep a set of numbers seen so far.
- Code it, then test it. Try an empty list, a single number and an all-equal list before you submit.
func containsDuplicate(nums []int) bool {
seen := map[int]bool{}
for _, n := range nums {
if seen[n] {
return true // met this number before
}
seen[n] = true
}
return false
}Step 4 is the whole skill. The rest of this site trains you to ask that question for every pattern.
Now you try it
Clear the code above from your head and write it yourself here, then press Run tests. It checks your answer against hidden tests, including a big one that is too slow for the nested-loop idea.
Write Go. Common packages like fmt and sort are imported for you. Keep the function name and inputs the same.
5. When you are stuck
Being stuck is normal. It is part of the lesson. Use this ladder, and only go down one step at a time:
- Nudge is a small push, like “what are you repeating?”
- Idea tells you the approach in words, with no code.
- Reference solution is the full code. Read it once, close it, then write it yourself.
6. What one good session looks like
- Pick one problem from the roadmap. Just one.
- Set a 20-minute timer and try alone on paper.
- Use a hint if the timer ends. Then code it and test it with small examples.
- Write two sentences in a notebook: what the trick was, and how you could spot it next time.
Those two sentences are worth more than the code. They are how you build your own pattern list.
7. Redo problems (the secret step)
Your brain forgets new things fast. But each time you pull an idea out of memory without looking, it fades more slowly. This is called spaced practice plus self-testing. In a famous review of ten study methods, these two came out on top, while re-reading and highlighting came out low.
| When | What to do |
|---|---|
| Day 0 | Solve it. Close the solution and type it again from memory. |
| Day 1 | Solve it again on a blank page. No notes. |
| Day 3–4 | Solve it again. Say the idea out loud first. |
| Day 7–10 | Again. If you stall, go back one step (the Idea hint) and shorten the next gap. |
| Day 30 | Last check. If it is easy, you own it. Retire the problem. |
The exact days are a simple plan based on several coders' advice; nobody has one proven schedule. What matters is that the gaps get longer. Use the Review page to practise recall with flashcards.
8. Learn the patterns
A pattern is a “if you see this, try that” rule. Here are the first ones to learn. You will meet each one in the roadmap:
| If the problem says… | Try | Example |
|---|---|---|
| “Have I seen this before?” | Hash set or map | Contains Duplicate, Two Sum |
| Sorted list, find a pair | Two pointers | Two Sum II, 3Sum |
| Best / longest / shortest sub-part of a list | Sliding window | Longest Substring Without Repeating Characters |
| Sorted data, or “find the smallest value that works” | Binary search | Binary Search, Koko Eating Bananas |
| Matching brackets, “undo” the last thing | Stack | Valid Parentheses |
| Every choice, try them all | Backtracking | Subsets, Permutations |
| Tree or grid, go deep or go wide | DFS / BFS | Number of Islands |
| Same small question again and again | Dynamic programming | Climbing Stairs, Coin Change |
9. How many problems, and how much time?
- Time: 45–60 minutes a day, 5 days a week, beats a 6-hour weekend. Short and regular wins because of the spacing effect above.
- Number: The Tech Interview Handbook plan is 75 problems over 3 months (about 11 hours a week). This site's roadmap has 150 problems. You do not need all of them to start applying.
- Quality: One problem you can explain and redo is worth more than five you only read.
10. Common mistakes
| Mistake | Do this instead |
|---|---|
| Staring at a blank editor for an hour | Set a 20-minute timer. Then use a hint. Struggling helps; being lost does not. |
| Reading the answer and moving on | Close it and type it yourself. Then redo it in a day. |
| Counting problems instead of learning | 50 problems done well beat 500 skimmed. Count patterns you can explain. |
| Memorising code | Memorised code breaks when the problem changes a little. Learn the idea behind it. |
| Never coming back | One solve is a guess. A solve three days later is proof. |
| Jumping to Hard problems | Stay on Easy and Medium until the patterns feel boring. |
11. A realistic first weeks
- Days 1–3Go basics, Big-O and recursion
Read Go for Interviews, the Big-O cheat sheet and Recursion Basics. Run one tiny Go program. Do not solve problems yet.
- Days 4–7Arrays & Hashing
Solve the 9 problems. Use the Nudge and Idea hints freely: the goal this week is the habit, not the score.
- Week 2Two Pointers, Stack, Binary Search
About 2 problems a day. Re-solve anything you needed the Idea for.
- Weeks 3–4Sliding Window, Linked List, Trees
Trees are the first topic where recursion is unavoidable, so do Recursion Basics first if you skipped it. Draw each example on paper.
- Weeks 5–10The rest of the map
Heap, Backtracking, Graphs, DP and the others, in map order. Keep a short list of problems to redo every Sunday.