This is your one-page reference for coding interviews. It covers every data structure, algorithm, and pattern from the entire DSA Tutorial series. Bookmark this page and review it before your next interview.

We show code templates in Python, Kotlin, and Go.

Data Structure Complexity

Data StructureAccessSearchInsertDeleteSpace
ArrayO(1)O(n)O(n)O(n)O(n)
Linked ListO(n)O(n)O(1)*O(1)*O(n)
StackO(n)O(n)O(1)O(1)O(n)
QueueO(n)O(n)O(1)O(1)O(n)
Hash MapO(1) avgO(1) avgO(1) avgO(n)
BST (balanced)O(log n)O(log n)O(log n)O(n)
HeapO(n)O(log n)O(log n)O(n)
TrieO(m)O(m)O(m)O(n*m)
Graph (adj list)O(V+E)O(1)O(E)O(V+E)
Union-FindO(α(n))O(n)

*With reference to the node. m = string length. α(n) = inverse Ackermann (effectively O(1)).

Sorting Algorithms

AlgorithmBestAverageWorstSpaceStable
Bubble SortO(n)O(n^2)O(n^2)O(1)Yes
Insertion SortO(n)O(n^2)O(n^2)O(1)Yes
Merge SortO(n log n)O(n log n)O(n log n)O(n)Yes
Quick SortO(n log n)O(n log n)O(n^2)O(log n)No
Heap SortO(n log n)O(n log n)O(n log n)O(1)No
Counting SortO(n+k)O(n+k)O(n+k)O(k)Yes

Big O Growth Rates

From fastest to slowest: O(1) < O(log n) < O(n) < O(n log n) < O(n^2) < O(2^n) < O(n!)

For n = 1,000,000:

  • O(log n) = ~20
  • O(n) = 1,000,000
  • O(n log n) = ~20,000,000
  • O(n^2) = 1,000,000,000,000 (too slow)

Code Templates

Python:

def binary_search(nums, target):
    left, right = 0, len(nums) - 1
    while left <= right:
        mid = left + (right - left) // 2
        if nums[mid] == target:
            return mid
        elif nums[mid] < target:
            left = mid + 1
        else:
            right = mid - 1
    return -1

Kotlin:

fun binarySearch(nums: IntArray, target: Int): Int {
    var left = 0; var right = nums.size - 1
    while (left <= right) {
        val mid = left + (right - left) / 2
        when {
            nums[mid] == target -> return mid
            nums[mid] < target -> left = mid + 1
            else -> right = mid - 1
        }
    }
    return -1
}

Go:

func binarySearch(nums []int, target int) int {
    left, right := 0, len(nums)-1
    for left <= right {
        mid := left + (right-left)/2
        if nums[mid] == target { return mid }
        if nums[mid] < target { left = mid + 1 } else { right = mid - 1 }
    }
    return -1
}

Sliding Window (Variable Size)

Python:

def sliding_window(s):
    window = {}
    left = result = 0
    for right in range(len(s)):
        window[s[right]] = window.get(s[right], 0) + 1
        while invalid(window):
            window[s[left]] -= 1
            if window[s[left]] == 0: del window[s[left]]
            left += 1
        result = max(result, right - left + 1)
    return result

BFS Template

Python:

from collections import deque

def bfs(graph, start):
    queue = deque([start])
    visited = {start}
    while queue:
        node = queue.popleft()
        for neighbor in graph[node]:
            if neighbor not in visited:
                visited.add(neighbor)
                queue.append(neighbor)

DFS Template

Python:

def dfs(graph, node, visited):
    visited.add(node)
    for neighbor in graph[node]:
        if neighbor not in visited:
            dfs(graph, neighbor, visited)

Backtracking Template

Python:

def backtrack(candidates, path, result):
    if is_solution(path):
        result.append(path[:])
        return
    for candidate in candidates:
        if is_valid(candidate, path):
            path.append(candidate)
            backtrack(candidates, path, result)
            path.pop()

Union-Find Template

Python:

class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n))
        self.rank = [0] * n

    def find(self, x):
        if self.parent[x] != x:
            self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def union(self, x, y):
        px, py = self.find(x), self.find(y)
        if px == py: return False
        if self.rank[px] < self.rank[py]: px, py = py, px
        self.parent[py] = px
        if self.rank[px] == self.rank[py]: self.rank[px] += 1
        return True

Dijkstra Template

Python:

import heapq

def dijkstra(graph, start):
    dist = {node: float("inf") for node in graph}
    dist[start] = 0
    heap = [(0, start)]
    while heap:
        d, node = heapq.heappop(heap)
        if d > dist[node]: continue
        for neighbor, weight in graph[node]:
            new_dist = d + weight
            if new_dist < dist[neighbor]:
                dist[neighbor] = new_dist
                heapq.heappush(heap, (new_dist, neighbor))
    return dist

Topological Sort (Kahn’s Algorithm)

Python:

from collections import deque

def topological_sort(graph, in_degree, n):
    queue = deque(i for i in range(n) if in_degree[i] == 0)
    order = []
    while queue:
        node = queue.popleft()
        order.append(node)
        for neighbor in graph[node]:
            in_degree[neighbor] -= 1
            if in_degree[neighbor] == 0:
                queue.append(neighbor)
    return order if len(order) == n else []

Trie Template

Python:

class TrieNode:
    def __init__(self):
        self.children = {}
        self.is_end = False

class Trie:
    def __init__(self):
        self.root = TrieNode()

    def insert(self, word):
        node = self.root
        for char in word:
            if char not in node.children:
                node.children[char] = TrieNode()
            node = node.children[char]
        node.is_end = True

    def search(self, word):
        node = self.root
        for char in word:
            if char not in node.children:
                return False
            node = node.children[char]
        return node.is_end

    def starts_with(self, prefix):
        node = self.root
        for char in prefix:
            if char not in node.children:
                return False
            node = node.children[char]
        return True

Pattern Recognition Quick Reference

If the problem says…Try this pattern
“Sorted array” + “find pair”Two Pointers
“Longest/shortest substring”Sliding Window
“Sorted” + “search” or “min of max”Binary Search
“Grid” or “graph” + “shortest”BFS
“All paths” or “connected components”DFS
“Min/max/count ways” + “overlapping”Dynamic Programming
“All combinations/permutations”Backtracking
“Next greater/smaller”Monotonic Stack
“K largest/smallest”Heap
“Intervals” + “merge/overlap”Sort + Merge Intervals
“Connected groups” or “union”Union-Find
“Prefix matching” or “autocomplete”Trie
“Ordering with dependencies”Topological Sort
“Weighted shortest path”Dijkstra

DP Pattern Quick Reference

PatternKey SignalExample
Linear DPPrevious 1-2 elementsClimbing Stairs, House Robber
0/1 KnapsackChoose/skip items, capacityPartition Equal Subset Sum
Unbounded KnapsackReuse itemsCoin Change
String DPTwo strings, compare charsEdit Distance, LCS
Grid DPMove right/downUnique Paths, Min Path Sum
Interval DPRange [i,j], split at kBurst Balloons
State MachineMultiple statesBuy/Sell Stock with Cooldown

Interview Checklist

Before coding:

  • Read the problem twice
  • Ask clarifying questions (edge cases, constraints, input size)
  • Identify the pattern (spend 2-3 minutes)
  • Explain your approach to the interviewer
  • Discuss time and space complexity before coding

While coding:

  • Write clean, readable code
  • Use meaningful variable names
  • Handle edge cases (empty input, single element, duplicates)
  • Think out loud

After coding:

  • Walk through a test case manually
  • Check edge cases
  • State the final time and space complexity
  • Ask: “Would you like me to optimize this?”

Common Interview Mistakes

  1. Starting to code before explaining your approach
  2. Not asking clarifying questions
  3. Ignoring edge cases
  4. Not testing your solution
  5. Getting stuck silently (always communicate)
  6. Using the wrong data structure
  7. Off-by-one errors in loops and binary search
  8. String concatenation in a loop (use StringBuilder/join)

Essential Problems by Pattern (Top 20)

#ProblemPatternDifficulty
1Two SumHash MapEasy
153SumTwo PointersMedium
3Longest Substring Without RepeatingSliding WindowMedium
33Search in Rotated Sorted ArrayBinary SearchMedium
200Number of IslandsDFSMedium
102Binary Tree Level OrderBFSMedium
70Climbing StairsDP (Linear)Easy
322Coin ChangeDP (Knapsack)Medium
78SubsetsBacktrackingMedium
739Daily TemperaturesMonotonic StackMedium
215Kth Largest ElementHeapMedium
56Merge IntervalsIntervalsMedium
208Implement TrieTrieMedium
207Course ScheduleTopological SortMedium
684Redundant ConnectionUnion-FindMedium
743Network Delay TimeDijkstraMedium
5Longest Palindromic SubstringTwo PointersMedium
76Minimum Window SubstringSliding WindowHard
72Edit DistanceDP (String)Medium
62Unique PathsDP (Grid)Medium

Series Complete

Congratulations — you have completed the entire DSA Tutorial series. You now have the knowledge to tackle coding interviews at any company. Remember: consistent practice beats last-minute cramming. Use the study plan from DSA-24, practice the patterns, and you will be ready.

Good luck with your interviews.

Full series: DSA from Zero to Interview Ready