Problem Bank (Flashcards)

A curated set of high-frequency problems grouped by pattern. Each is a flashcard: read the prompt, decide your approach, then reveal the optimal idea and complexity.

problem-bankleetcodedrills

Your pattern gym — train recognition, not memorization

Think of this page as flashcard training for your brain's pattern-recognition circuits. A real interview isn't "write the code for Two Sum" — it's "here's a problem you've never seen; figure out which type of problem it is." These flashcards train exactly that skill: read the problem, say the approach, then reveal.

🎯 How to use: For each card, say your approach and its Big-O out loud before revealing. Then mark "Knew it" or "Revise again". The goal is instant pattern recognition, not memorizing code.

Stuck on 'how would I even start?'

That's a trained skill, not a talent. Read How to Think (the Interview Cheat Code) first — it gives you the clue → pattern decoder table and walks you through the questions to ask yourself on real problems. Then come back and drill.

Complexity cheat-sheet for this bank

PatternTimeSpaceKey data structure
Hash map lookupO(1) avgO(n)Hash table
Sliding windowO(n)O(1)–O(k)Two pointers + hash/set
Binary searchO(log n)O(1)
Stack / monotonicO(n)O(n)Stack
BFS / DFS on graphO(V+E)O(V)Queue / recursion
Min/max heapO(n log k)O(k)Heap
DP (1-D)O(n · states)O(n)Array
BacktrackingO(n · n!) worstO(n) stackRecursion

Code pattern references

The key operations used across all problems below — in all three languages:

Python
# Core data structures
from collections import defaultdict, deque
import heapq

seen = {}                            # hash map: O(1) lookup/insert
stack = []                           # stack: append/pop
queue = deque()                      # queue: appendleft/popleft
min_heap = []                        # min-heap
heapq.heappush(min_heap, val)        # O(log n)
top = heapq.heappop(min_heap)        # O(log n)
Java
import java.util.*;

// Core data structures in Java
Map<Integer, Integer> map = new HashMap<>();   // O(1) lookup
Deque<Integer> stack = new ArrayDeque<>();     // stack: push/pop
Queue<Integer> queue = new LinkedList<>();     // BFS queue
PriorityQueue<Integer> minHeap = new PriorityQueue<>();  // min-heap
minHeap.offer(val);  // O(log n)
int top = minHeap.poll();  // O(log n)
C++
#include <unordered_map>
#include <stack>
#include <queue>
#include <vector>
using namespace std;

unordered_map<int, int> umap;   // O(1) average lookup
stack<int> stk;                  // stack
queue<int> bfsQ;                 // BFS queue
priority_queue<int, vector<int>, greater<int>> minHeap;  // min-heap
minHeap.push(val);               // O(log n)
int top = minHeap.top(); minHeap.pop();  // O(log n)

Arrays, strings & hashing

Stacks & linked lists

Trees

Graphs

Heaps & intervals

DP

Backtracking & greedy

Think it through

Before revealing — what pattern does this problem belong to, and what's your Big-O?

Think it through: Flash: Pattern Recognition Speed TestMixed — 5 problems in 5 minutes0/5 stages

PROBLEMFor each of the five problems below, decide the pattern BEFORE looking at the answer. Time yourself. (1) 'Find the median from a data stream as numbers are added.' (2) 'Given a grid of 0s and 1s, find the largest connected region of 1s.' (3) 'Return all valid parentheses strings of length 2n.' (4) 'Minimum cost to connect all points in a 2D plane.' (5) 'Longest palindromic substring.'

  1. 1

    Problem 1: Median from stream

    Numbers arrive one by one. You need the median at any point. What structure gives you both the lower and upper halves instantly?

  2. 2

    Problem 2: Largest connected region

    Grid, connectivity, find regions — what pattern?

    unlocks after the stage above
  3. 3

    Problem 3: All valid parentheses strings

    'Return ALL valid strings' — what does 'all' always signal?

    unlocks after the stage above
  4. 4

    Problem 4: Minimum cost to connect all points

    Connect all nodes with minimum total edge weight — classic name for this?

    unlocks after the stage above
  5. 5

    Problem 5: Longest palindromic substring

    Palindromes are symmetric. What's the O(n) insight instead of checking every substring?

    unlocks after the stage above

Practice — climb the ladder

Practice ladder: Problem Bank Patterns0/9 solved

Climb in order — every rung assumes the one above it. Solve on LeetCode, then tick it here; progress is saved on this device.

Foundational

one pattern per problem, instant recognition
  1. Hash map complement lookup — the O(n²)→O(n) upgrade.

  2. Stack — LIFO mirrors nesting.

  3. 1-D DP / Fibonacci — 'ways to reach' = DP fingerprint.

Core flashcard set

medium problems where the pattern isn't immediately obvious
  1. Sliding window — expand right, shrink left on duplicate.

  2. Prefix × suffix pass, no division, O(1) extra.

  3. Min-heap of end times — classic interval sweep.

  4. Topological sort / cycle detection — Kahn's BFS.

Stretch

compound patterns
  1. Two-heap trick — always accessible median.

  2. Min-heap over k heads — O(N log k).

Check yourself — instant pattern recognition

Check yourself0/3 answered

1. 'Given a string, find the longest substring with at most 2 distinct characters.' Which pattern?

2. For 'Kth largest element in a stream', which is correct?

3. Two Sum with a SORTED array — which is more space-efficient than a hash map?

Visualize the hash map in action

Unknown visualizer: hash-map