Which data structures and algorithms questions come up most often, and how should you prioritise them?
A small set of questions accounts for a large share of what gets asked. Arrays and hash maps dominate: two sum, group anagrams, longest substring without repeating characters, subarray sum equals k. Then linked lists: reverse a list, detect a cycle, merge two sorted lists, find the middle. Then trees and graphs: traversals, validate a search tree, lowest common ancestor, number of islands, course schedule.
from collections import Counter
recent = [
"two sum", "two sum", "valid parentheses", "two sum",
"reverse linked list", "valid parentheses", "binary search",
"two sum", "merge intervals", "valid parentheses",
]
def most_common(items, n=3):
return Counter(items).most_common(n)
print(most_common(recent))The output is the three highest counts, two sum with four, valid parentheses with three and reverse linked list with one. The counts come from this sample, but the ranking reflects what interviewers really ask.
The mechanism is that those questions are asked because they are compact, they have a clear optimal solution, and they discriminate well between candidates. Two sum tests whether you reach for a hash map. Number of islands tests whether you can do a flood fill. Valid parentheses tests whether you know when a stack is the right structure.
The trade-off to name is the temptation to memorise solutions for the top ten and stop there. That works for one interview and fails for the next one, because the follow-up questions on a familiar problem are where the real skill is tested. A better allocation of time is to practise a smaller set deeply enough that you can solve variations, then cover the long tail by recognising the pattern rather than by memorising the code.