Question Bank
Every question, one list
Sandboxed coding rounds that run against a hidden test suite, and written questions graded against a rubric — side by side, because when you are drilling a topic you want both.
Topicimplementation (105)system-design (24)hld (20)trees (11)distributed-systems (10)arrays-hashing (9)concurrency (9)graphs (9)binary-search (8)consistency (8)dp-1d (8)linked-list (8)reliability (8)storage (8)
Clear filters20 questions · browse by bank instead
- Best Time to Buy and Sell StockWrite `max_profit(prices)` returning the best profit from one buy and one later sell. If no trade is profitable, return `0`. max_profit([7, 1, 5, 3, 6, 4]) -> 5 (buy at 1, sell at 6) maeasyCoderpad#implementation#sliding-window
- Binary SearchWrite `search(nums, target)` returning the index of `target` in the ascending list, or `-1`. search([-1, 0, 3, 5, 9, 12], 9) -> 4 search([-1, 0, 3, 5, 9, 12], 2) -> -1 Everyone knows thieasyCoderpad#binary-search#implementation
- Climbing StairsWrite `climb_stairs(n)` counting the distinct ways to climb `n` steps taking 1 or 2 at a time. climb_stairs(3) -> 3 (1+1+1, 1+2, 2+1) Ways to reach step n is ways(n-1) + ways(n-2) — it is FieasyCoderpad#dp-1d#implementation
- Contains DuplicateWrite `has_duplicate(nums)` that returns `True` when any value appears more than once in the list, and `False` when every value is distinct. has_duplicate([1, 2, 3, 1]) -> True has_duplicateasyCoderpad#arrays-hashing#implementation
- Diameter of Binary TreeWrite `diameter_of_binary_tree(root)` returning the number of edges on the longest path between any two nodes. The path need not pass through the root. [1,2,3,4,5] -> 3 (4 -> 2 -> 1 -> 3) TheasyCoderpad#implementation#trees
- Invert Binary TreeWrite `invert_tree(root)` swapping every left and right child, and returning the root. The code is four lines. What the interviewer is listening for is whether you can name what you are doing — this easyCoderpad#implementation#trees
- Kth Largest Element in a StreamImplement `KthLargest(k, nums)` with `add(val)` returning the kth largest value seen so far. Keeping everything sorted is O(n log n) per add. Keep a *min*-heap of exactly the k largest values insteadeasyCoderpad#heap#implementation
- Last Stone WeightWrite `last_stone_weight(stones)` simulating this: repeatedly take the two heaviest stones and smash them. Equal weights destroy both; otherwise the difference goes back into the pile. Return the lasteasyCoderpad#heap#implementation
- Linked List CycleWrite `has_cycle(head)` returning `True` when the list contains a cycle. A set of visited nodes works and costs O(n) memory. The expected answer is Floyd: a slow pointer moving one step and a fast oneasyCoderpad#implementation#linked-list
- Maximum Depth of Binary TreeWrite `max_depth(root)` returning the number of nodes on the longest path from the root down to a leaf. An empty tree has depth 0. The recursive answer is one line. The reason this is asked at all iseasyCoderpad#implementation#trees
- Merge Booking WindowsA room booking system stores reservations as `(start, end)` minute offsets from midnight. Overlapping and touching reservations should be collapsed into single continuous blocks before they are shown easyCoderpad#implementation
- Merge Two Sorted ListsWrite `merge_two_lists(a, b)` merging two ascending lists into one ascending list and returning its head. Splice the existing nodes rather than allocating new ones. [1,2,4] and [1,3,4] -> [1,1,easyCoderpad#implementation#linked-list
- Number of 1 BitsWrite `hamming_weight(n)` counting the set bits in a non-negative integer. hamming_weight(11) -> 3 (1011) Shifting 32 times works. `n & (n - 1)` clears the lowest set bit, so the loop runs oeasyCoderpad#bit-math#implementation
- Reverse Linked ListWrite `reverse_list(head)` returning the head of the reversed list. 1 -> 2 -> 3 becomes 3 -> 2 -> 1 Save the next node before you overwrite the current pointer, or the rest of the list is goneeasyCoderpad#implementation#linked-list
- Single NumberWrite `single_number(nums)` where every value appears twice except one. Return the one. Use O(1) extra space. single_number([4,1,2,1,2]) -> 4 A hash map solves it in O(n) space, which the conseasyCoderpad#bit-math#implementation
- Subtree of Another TreeWrite `is_subtree(root, sub)` returning `True` when `sub` appears as a subtree of `root` — matching a node and *all* of its descendants exactly. This is two problems: an exact same-tree comparison, aeasyCoderpad#implementation#trees
- Two SumWrite `two_sum(nums, target)` that returns the indices of the two values summing to `target`, as a tuple `(i, j)` with `i < j`. Exactly one such pair exists. two_sum([2, 7, 11, 15], 9) -> (0, 1easyCoderpad#arrays-hashing#implementation
- Valid AnagramWrite `is_anagram(a, b)` that returns `True` when the two strings contain exactly the same characters with the same multiplicities. is_anagram("listen", "silent") -> True is_anagram("rat", easyCoderpad#arrays-hashing#implementation
- Valid PalindromeWrite `is_palindrome(s)` that returns `True` when the string reads the same forwards and backwards, ignoring case and skipping anything that is not a letter or digit. is_palindrome("A man, a planeasyCoderpad#implementation#two-pointers
- Valid ParenthesesWrite `is_valid(s)` returning `True` when every bracket in the string closes in the right order. The string contains only `()[]{}`. is_valid("()[]{}") -> True is_valid("(]") -> False easyCoderpad#implementation#stack