Skip to content
QSWEQB

Data Structures & Algorithms interview questions

Coding-round questions organised by the pattern they test rather than by problem name, so you learn transferable techniques instead of memorising individual puzzles.

21 published across 16 topics.

Data structures and algorithms fundamentals54 short answers on one page, for revising rather than studying.

Arrays & Strings

2 questions

In-place manipulation, prefix sums, and the string-scanning problems that open most coding rounds.

mediumCoding

Rotate an array k positions to the right, in place.

Reverse the whole array, then reverse the first k elements and the remaining n minus k separately. Three linear reversals rotate in place with no second array, cost n swaps, and the whole thing collapses if you forget to reduce k modulo n first.

4 minentry, mid, senior

Hashing & Maps

1 question

Trading memory for time with hash maps and sets, plus the collision and ordering caveats interviewers probe.

mediumCodingConcept

Count the subarrays whose elements sum to k, where the values may be negative.

Keep a running prefix sum and a map from prefix-sum value to how many times it has occurred; at each index the number of subarrays ending there is the count already recorded for sum minus k. That is O(n) time for O(n) memory, and the map is what lets it tolerate negative numbers where a sliding window cannot.

4 minmid, senior

Two Pointers & Sliding Window

2 questions

Linear-time techniques for subarray and pair-finding problems that naively look quadratic.

mediumCoding

Find the length of the longest substring without repeating characters.

Maintain a sliding window with a map from character to its last seen index; when a duplicate appears inside the current window, jump the left boundary past that previous occurrence rather than shrinking one step at a time, giving a single-pass O(n) solution.

2 minentry, mid, senior
mediumCoding

Return every distinct triplet in the array that sums to zero.

Sort the array, fix each element as an anchor, then converge two pointers inwards from both ends of the remaining range. The sort is asymptotically free against the O of n squared scan, and it is what lets you skip duplicate values positionally instead of deduplicating a set of results afterwards.

4 minentry, mid, senior

Linked Lists

1 question

Pointer surgery: reversal, cycle detection, merging, and the off-by-one errors that reveal carelessness.

Stacks & Queues

1 question

Monotonic stacks, deques, and the parsing and next-greater-element families.

Trees & BSTs

2 questions

Traversals, recursion versus iteration, balancing, and lowest-common-ancestor problems.

mediumCoding

Find the lowest common ancestor of two nodes in a binary tree.

Recurse post-order and return the node whose left and right subtrees each report back one target; if only one side reports back, propagate that result upwards. This is O(n) time and O(h) stack. A BST lets you descend by value comparison instead, and parent pointers reduce it to list intersection.

5 minentry, mid, senior
mediumCoding

Given a binary tree, decide whether it is a valid binary search tree.

Every node must fall inside an open interval inherited from its ancestors, not merely compare correctly against its own two children. Recurse carrying a low and high bound, tightening one of them at each descent, or walk in-order and require the sequence to be strictly increasing.

5 minentry, mid, senior

Graphs

2 questions

BFS, DFS, topological sort, shortest paths, and union-find, including spotting a graph problem in disguise.

Heaps & Priority Queues

1 question

Top-K, streaming medians, and merges where partial ordering beats full sorting.

Dynamic Programming

2 questions

State definition, transitions, and the memoisation-to-tabulation conversion most candidates fumble.

mediumCodingConcept

How do you know a problem is dynamic programming?

Dynamic programming applies when subproblems overlap and optimal substructure holds. Define the state as the minimum set of parameters that makes the remaining decisions independent of the path taken to reach them, then tabulate by filling states in the reverse of the recursion's dependency order.

5 minmid, senior

Greedy Algorithms

1 question

Exchange arguments and proving a locally optimal choice is globally safe.

mediumCodingConcept

How do you know a greedy choice is safe and not merely plausible?

A greedy choice is safe when you can show at least one optimal solution contains it, usually via an exchange argument that swaps an optimum's first choice for yours without losing anything. Interval scheduling by earliest finish time admits that swap; coin change with arbitrary denominations does not.

4 minmid, senior, staff

Recursion & Backtracking

1 question

Permutations, combinations, constraint satisfaction, and pruning to keep search tractable.

Sorting & Searching

1 question

Binary search on answers, custom comparators, and sorting internals still asked about.

Intervals

1 question

Merging, overlap detection, and sweep-line scheduling problems.

easyCoding

Merge a list of overlapping intervals, and justify the key you sorted by

Sorting by start time is what reduces the merge to a single scan carrying one scalar, the end of the open block; sorting by end breaks it, and sorting by end is instead correct for maximum non-overlapping selection. Both run in O(n log n), and equal timestamps decide the answer.

4 minentry, mid, senior

Bit Manipulation

1 question

Masks, XOR tricks, and the low-level questions in systems-leaning interviews.

Tries & Advanced Strings

1 question

Prefix trees, autocomplete, and pattern matching for search-heavy roles.

Complexity Analysis

1 question

Deriving and defending time and space bounds, including amortised reasoning.