Coding interview prep · Java edition

DSA Field Guide

Every data structures and algorithms topic you need for product-company interviews — from Big-O to segment trees — explained in plain words, with a real-life picture, a cost table, a Java template, and hand-picked LeetCode problems for each.

    How to use this guide

    Go top to bottom, one topic at a time. Each level builds on the one before. A single 45-minute session looks like this:

    1. Read (10 min)"In simple words", the analogy, and the key ideas for today's topic.
    2. Type the template (5 min)Close the page and write the Java code from memory. Compare.
    3. Solve one problem (25 min)Start with the Easy ones, then Medium. Stuck for 20 minutes? Read a solution, then re-solve it tomorrow without help.
    4. Note it (5 min)Write one line: the pattern you used and the mistake you made.

    Tick Mark done once you've solved 3–5 problems from a topic. Your ticks are saved in this browser only.

    Solving a problem in the interview

    1. UnderstandRepeat the problem in your words. Ask about input size, value ranges, duplicates, empty input.
    2. ExamplesWalk through the given example and add one edge case of your own.
    3. Brute forceSay the simple solution and its complexity, even if it's slow.
    4. OptimizeFind the bottleneck and name the pattern ("this is a sliding window").
    5. CodeClear names, small helper methods, talk while you type.
    6. TestDry-run your code on the example, then on the edge cases.
    7. ComplexityFinish with time and space, without being asked.

    Pattern finder

    Read the problem, find the clue on the left, try the technique on the right.

    If the problem says…Try

    Complexity at a glance

    StructureAccessSearchInsertDeleteSpace
    ArrayO(1)O(n)O(n)O(n)O(n)
    ArrayList (at end)O(1)O(n)O(1)*O(1)O(n)
    Linked list (at head)O(n)O(n)O(1)O(1)O(n)
    Stack / Queue (ArrayDeque)top/front O(1)O(n)O(1)O(1)O(n)
    HashMap / HashSetO(1) avgO(1) avgO(1) avgO(n)
    TreeMap / balanced BSTO(log n)O(log n)O(log n)O(log n)O(n)
    Binary heap (PriorityQueue)top O(1)O(n)O(log n)top O(log n)O(n)
    TrieO(L)O(L)O(L)O(chars × alphabet)
    Union-Findfind ≈ O(1)union ≈ O(1)O(n)
    Segment / Fenwick treerange O(log n)update O(log n)O(n)

    * amortized · L = word length

    Edge cases to test every time

    • Empty input, one element, two elements
    • All elements equal; many duplicates
    • Negative numbers and zero
    • Very large values → int overflow, use long
    • Already sorted and reverse sorted input
    • null head / root; single-node tree; skewed tree
    • Disconnected graph; graph with a cycle; self-loops
    • Target not present; answer at the first or last index

    Where to practise

    • LeetCode — every problem in this guide links there
    • NeetCode 150 — curated list grouped by pattern
    • GeeksforGeeks — theory and company-wise questions
    • VisuAlgo — animations of sorting, trees and graphs
    Problem difficulty: E Easy M Medium H Hard