How to study

Step-by-step coding interview framework

Use this checklist on every coding question — in practice and in real interviews.

Step 1: Read and clarify

Restate the problem in your own words. Ask about input size, edge cases (empty input, duplicates, negative numbers), and expected output format. Confirm whether you can modify the input or need extra space.

Step 2: Walk through examples

Trace 2–3 examples by hand, including a small case and an edge case. Write down expected outputs before you design an algorithm.

Step 3: Start with brute force

Describe the naive solution first — nested loops, full sort, or exhaustive search. State its time and space complexity. Interviewers want to see you can solve it before you optimize.

Step 4: Spot the pattern

Look for signals: sorted input → two pointers or binary search; top-k / streaming → heap; fast lookup → hash map; ordering + eviction → linked list + map; intervals → sort or sweep line; graph → BFS/DFS.

Step 5: Design the optimized approach

Explain your data structures and the main loop in plain English before coding. For each operation, state why it is O(1) or O(log n). Draw a quick diagram if it helps.

Step 6: Implement and test

Write clean code with meaningful names. After coding, walk through your earlier examples and one edge case out loud. Fix off-by-one errors and null checks.

Step 7: Analyze complexity

State time and space complexity and justify them. Mention trade-offs (memory vs speed, preprocessing vs query time). Be ready for follow-ups: thread safety, scale, or API changes.

Each question below includes its own step-by-step study guide. Read the guide first, then try the problem before unlocking the full solution.