← Practice
Mock Interview Problems
The executable half of the bank: timed problems checked against a hidden test suite, rather than graded against a rubric. Build something from scratch, or find and fix a real bug in code that is already there.
108 questions
- 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
- Thread-Safe CounterImplement a `ThreadSafeCounter` class with two methods: - `increment()` — increments the counter by 1. - `value()` — returns the current count. Multiple threads will call `increment()` concurrently.mediumCoderpad#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
- Fix: Deduplicate While Preserving OrderYou've inherited a small utility function, `dedupe_preserving_order`, from a teammate. Product just filed a bug: a list of a user's recently-viewed items comes back in a strange, seemingly scrambled oeasyCoderpad#debugging
- 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
- Group AnagramsWrite `group_anagrams(words)` that groups the input into lists of mutual anagrams. Return a list of groups; order within a group and between groups does not matter. group_anagrams(["eat", "tea", mediumCoderpad#arrays-hashing#implementation
- Top K Frequent ElementsWrite `top_k_frequent(nums, k)` returning the `k` most frequent values, in any order. top_k_frequent([1, 1, 1, 2, 2, 3], 2) -> [1, 2] Sorting by count is O(n log n) and a size-k heap is O(n lomediumCoderpad#arrays-hashing#implementation
- Product of Array Except SelfWrite `product_except_self(nums)` returning a list where each position holds the product of every other element. product_except_self([1, 2, 3, 4]) -> [24, 12, 8, 6] Division is banned, and themediumCoderpad#arrays-hashing#implementation
- Encode and Decode StringsImplement `encode(strings)` and `decode(text)` so that `decode(encode(xs)) == xs` for any list of strings, including empty strings and strings containing any character at all. encode(["hi", "thermediumCoderpad#arrays-hashing#implementation
- Valid SudokuWrite `is_valid_sudoku(board)` for a 9x9 board given as a list of 9 lists of single-character strings, where `"."` marks an empty cell. Return `True` if no row, column, or 3x3 box contains a repeated mediumCoderpad#arrays-hashing#implementation
- Longest Consecutive SequenceWrite `longest_consecutive(nums)` returning the length of the longest run of consecutive integers present in the list. The values are unsorted and may repeat. longest_consecutive([100, 4, 200, 1,mediumCoderpad#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
- 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
- Two Sum II — Sorted InputWrite `two_sum_sorted(nums, target)` where `nums` is sorted ascending. Return the 0-based indices `(i, j)` with `i < j` of the two values summing to `target`. Exactly one answer exists. Use O(1) extramediumCoderpad#implementation#two-pointers
- Rolling MaximumA monitoring dashboard shows the highest value seen in the last `k` samples, updated on every new sample. Implement `rolling_max(values, k)`, returning a list of the maximum of every contiguous windomediumCoderpad#implementation
- 3SumWrite `three_sum(nums)` returning every distinct triplet that sums to zero. Each triplet must be sorted ascending, and no triplet may appear twice. Order of the triplets themselves does not matter. mediumCoderpad#implementation#two-pointers
- Kth Largest in a StreamValues arrive one at a time and never stop. After each arrival, report the kth largest value seen so far. Implement a `KthLargest` class: - `KthLargest(k)` — construct for a fixed k. - `add(value)` mediumCoderpad#implementation
- Container With Most WaterWrite `max_area(heights)` where `heights[i]` is the height of a vertical line at position `i`. Return the largest area of water any two lines can hold: `min(h[i], h[j]) * (j - i)`. max_area([1, 8mediumCoderpad#implementation#two-pointers
- Suppress Duplicate AlertsAn alerting pipeline fires the same alert repeatedly while a condition persists. You need to suppress duplicates: an alert with a given key should only pass through if that key has not been seen in thmediumCoderpad#implementation
- Trapping Rain WaterWrite `trap(heights)` returning the total units of water trapped between the bars after rain. trap([0,1,0,2,1,0,1,3,2,1,2,1]) -> 6 Water above any bar is `min(max_left, max_right) - height`. PhardCoderpad#implementation#two-pointers
- Fix: The Invoice That Does Not BalanceAn invoicing service splits a total across several line items and then verifies the parts sum back to the whole. It fails intermittently in production with "invoice does not balance", and nobody can rmediumCoderpad#debugging
- 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
- Fix: The Page That Skips RowsAn API paginates results with a cursor. Users report that occasionally a record they know exists never appears on any page — and sometimes one appears twice. `paginate(rows, cursor, limit)` returns `easyCoderpad#debugging
- Longest Substring Without Repeating CharactersWrite `length_of_longest_substring(s)` returning the length of the longest run of characters with no repeats. length_of_longest_substring("abcabcbb") -> 3 ("abc") length_of_longest_substrmediumCoderpad#implementation#sliding-window
- Longest Repeating Character ReplacementWrite `character_replacement(s, k)` returning the length of the longest substring that can be made of one repeated character by replacing at most `k` characters. character_replacement("AABABBA", mediumCoderpad#implementation#sliding-window
- Permutation in StringWrite `contains_permutation(pattern, text)` returning `True` when any permutation of `pattern` appears as a contiguous substring of `text`. contains_permutation("ab", "eidbaooo") -> True ("bmediumCoderpad#implementation#sliding-window
- Minimum Window SubstringWrite `min_window(s, t)` returning the shortest substring of `s` containing every character of `t` including duplicates. Return `""` when no such window exists. min_window("ADOBECODEBANC", "ABC")hardCoderpad#implementation#sliding-window
- Sliding Window MaximumWrite `max_sliding_window(nums, k)` returning the maximum of every contiguous window of width `k`, left to right. max_sliding_window([1,3,-1,-3,5,3,6,7], 3) -> [3, 3, 5, 5, 6, 7] A heap gives hardCoderpad#implementation#sliding-window
- 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
- Min StackImplement a `MinStack` class with `push(x)`, `pop()`, `top()` and `get_min()`, all in O(1). Scanning for the minimum on demand is O(n) and defeats the exercise. Keep a second stack of minima alongsidmediumCoderpad#implementation#stack
- Evaluate Reverse Polish NotationWrite `eval_rpn(tokens)` evaluating a list of tokens in postfix notation. Tokens are integers as strings, or one of `+ - * /`. Division truncates toward zero. eval_rpn(["2", "1", "+", "3", "*"]) mediumCoderpad#implementation#stack
- Daily TemperaturesWrite `daily_temperatures(temps)` returning, for each day, how many days you wait for a warmer one. Use `0` when no warmer day follows. daily_temperatures([73,74,75,71,69,72,76,73]) -> [1,1,4,2mediumCoderpad#implementation#stack
- Largest Rectangle in HistogramWrite `largest_rectangle_area(heights)` returning the area of the largest rectangle that fits under the histogram. largest_rectangle_area([2, 1, 5, 6, 2, 3]) -> 10 (heights 5 and 6, width 2) hardCoderpad#implementation#stack
- 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
- Search a 2D MatrixWrite `search_matrix(matrix, target)` returning `True` if the value is present. Each row is sorted ascending, and the first value of a row is greater than the last value of the row above. search_mediumCoderpad#binary-search#implementation
- Koko Eating BananasWrite `min_eating_speed(piles, h)` returning the smallest integer speed `k` such that eating `k` bananas per hour finishes every pile within `h` hours. A pile takes `ceil(pile / k)` hours and a partiamediumCoderpad#binary-search#implementation
- Find Minimum in Rotated Sorted ArrayWrite `find_min(nums)` returning the smallest value in an ascending array that has been rotated an unknown number of times. All values are distinct. find_min([3, 4, 5, 1, 2]) -> 1 find_min(mediumCoderpad#binary-search#implementation
- Search in Rotated Sorted ArrayWrite `search_rotated(nums, target)` returning the index of the target in a rotated ascending array of distinct values, or `-1`. search_rotated([4, 5, 6, 7, 0, 1, 2], 0) -> 4 search_rotatedmediumCoderpad#binary-search#implementation
- Median of Two Sorted ArraysWrite `find_median_sorted_arrays(a, b)` returning the median of the two ascending arrays combined, as a float. find_median_sorted_arrays([1, 3], [2]) -> 2.0 find_median_sorted_arrays([1,hardCoderpad#binary-search#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
- 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
- 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
- Remove Nth Node From End of ListWrite `remove_nth_from_end(head, n)` removing the nth node counted from the end, and returning the head. [1,2,3,4,5], n = 2 -> [1,2,3,5] Counting the length first and walking again is two passmediumCoderpad#implementation#linked-list
- Reorder ListWrite `reorder_list(head)` reordering the list in place to `first, last, second, second-last, ...`. Return nothing; modify the nodes. [1,2,3,4] -> [1,4,2,3] [1,2,3,4,5] -> [1,5,2,4,3] mediumCoderpad#implementation#linked-list
- Copy List with Random PointerEach node has a `next` and a `random` pointer that may target any node or `None`. Write `copy_random_list(head)` returning a deep copy: entirely new nodes, with the same structure. The difficulty is mediumCoderpad#implementation#linked-list
- LRU CacheImplement `LRUCache(capacity)` with `get(key)` returning the value or `-1`, and `put(key, value)`. When the cache is full, evict the least recently used entry. Both operations must be O(1). Neither smediumCoderpad#implementation#linked-list
- Merge k Sorted ListsWrite `merge_k_lists(lists)` merging `k` ascending linked lists into one and returning its head. The input may contain empty lists. Merging them one at a time into an accumulator is O(n k) — say so, hardCoderpad#implementation#linked-list
- 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
- 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
- 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
- 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
- Lowest Common Ancestor of a BSTWrite `lowest_common_ancestor(root, p, q)` returning the deepest node that is an ancestor of both. Nodes are node objects, both present in the tree, and a node counts as its own ancestor. In a generamediumCoderpad#implementation#trees
- Binary Tree Level Order TraversalWrite `level_order(root)` returning a list of lists, one per level, top to bottom and left to right. [3,9,20,null,null,15,7] -> [[3], [9, 20], [15, 7]] A plain BFS visits nodes in the right ormediumCoderpad#implementation#trees
- Binary Tree Right Side ViewWrite `right_side_view(root)` returning the values visible when looking at the tree from the right, top to bottom. [1,2,3,null,5,null,4] -> [1, 3, 4] Walking down the right spine is the obvioumediumCoderpad#implementation#trees
- Validate Binary Search TreeWrite `is_valid_bst(root)` returning `True` when every node in the left subtree is strictly less than the node, and every node in the right subtree is strictly greater — for *all* nodes, not just immemediumCoderpad#implementation#trees
- Kth Smallest Element in a BSTWrite `kth_smallest(root, k)` returning the kth smallest value (1-indexed) in the BST. An in-order traversal of a BST visits values in ascending order, so this is "stop after k visits." Collecting evmediumCoderpad#implementation#trees
- Binary Tree Maximum Path SumWrite `max_path_sum(root)` returning the largest sum along any path between two nodes. The path follows parent-child edges, need not touch the root, and must contain at least one node. Values may be nhardCoderpad#implementation#trees
- Serialize and Deserialize Binary TreeImplement `serialize(root)` returning a string, and `deserialize(data)` rebuilding the tree, so that the round trip preserves the tree exactly. Pre-order with an explicit marker for every missing chihardCoderpad#implementation#trees
- Implement TrieImplement `Trie` with `insert(word)`, `search(word)` returning whether the exact word was inserted, and `starts_with(prefix)`. The one thing that separates a working trie from a broken one is markingmediumCoderpad#implementation#tries
- Design Add and Search WordsImplement `WordDictionary` with `add_word(word)` and `search(word)`, where `.` in a search matches any single character. add_word("bad"); search("b..") -> True Without the wildcard this is a pmediumCoderpad#implementation#tries
- Word Search IIWrite `find_words(board, words)` returning every word from the list that can be spelt by walking adjacent cells (up, down, left, right) without reusing a cell in a single word. Return them in any ordehardCoderpad#implementation#tries
- 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
- K Closest Points to OriginWrite `k_closest(points, k)` returning the k points closest to the origin, in any order. Each point is a two-element list. k_closest([[1,3],[-2,2]], 1) -> [[-2,2]] Never call `sqrt`: it costs mediumCoderpad#heap#implementation
- Kth Largest Element in an ArrayWrite `find_kth_largest(nums, k)` returning the kth largest value (1-indexed). Duplicates count separately, so in `[3,3,1]` the 2nd largest is `3`. Sorting is O(n log n) and a size-k heap is O(n log mediumCoderpad#heap#implementation
- Find Median from Data StreamImplement `MedianFinder` with `add_num(num)` and `find_median()` returning the median of everything added so far, as a float. Keep a max-heap of the lower half and a min-heap of the upper half. Fix ahardCoderpad#heap#implementation
- SubsetsWrite `subsets(nums)` returning every subset of a list of distinct integers. Order does not matter, but no subset may repeat. subsets([1,2,3]) -> 8 subsets, including [] and [1,2,3] At each inmediumCoderpad#backtracking#implementation
- Combination SumWrite `combination_sum(candidates, target)` returning every unique combination of distinct candidates summing to the target. Each candidate may be reused any number of times. Order within and between mediumCoderpad#backtracking#implementation
- PermutationsWrite `permutations(nums)` returning every ordering of a list of distinct integers, in any order. permutations([1,2,3]) -> 6 orderings Unlike Subsets there is no start index: every unused elemmediumCoderpad#backtracking#implementation
- Word SearchWrite `exist(board, word)` returning `True` when the word can be spelt by walking adjacent cells (up, down, left, right) without reusing a cell. The whole problem is the visited bookkeeping. OverwritmediumCoderpad#backtracking#implementation
- Palindrome PartitioningWrite `partition(s)` returning every way to cut the string so that every piece is a palindrome. partition("aab") -> [["a","a","b"], ["aa","b"]] Generating all 2^(n-1) partitions and filtering mediumCoderpad#backtracking#implementation
- N-QueensWrite `solve_n_queens(n)` returning every board on which `n` queens share no row, column, or diagonal. Each board is a list of `n` strings using `Q` and `.`. Place one queen per row, so rows never cohardCoderpad#backtracking#implementation
- Number of IslandsWrite `num_islands(grid)` counting connected groups of `"1"` cells in a grid of `"1"` and `"0"`. Cells connect up, down, left and right — not diagonally. Scan for an unvisited land cell, count it, thmediumCoderpad#graphs#implementation
- Max Area of IslandWrite `max_area_of_island(grid)` returning the number of cells in the largest connected group of `1`s, or `0` when there is no land. The grid holds integers. Identical traversal to Number of Islands mediumCoderpad#graphs#implementation
- Clone GraphWrite `clone_graph(node)` returning a deep copy of a connected undirected graph. Each node has `val` and `neighbors`. The graph has cycles, so a naive traversal never terminates. Keep a map from origmediumCoderpad#graphs#implementation
- Rotting OrangesWrite `oranges_rotting(grid)` where `0` is empty, `1` is fresh and `2` is rotten. Each minute, rot spreads to fresh neighbours. Return the minutes until none are fresh, or `-1` if some can never rot. mediumCoderpad#graphs#implementation
- Surrounded RegionsWrite `solve(board)` flipping every `"O"` region fully surrounded by `"X"` into `"X"`, modifying the board in place. A region touching the border is not surrounded. [["X","X","X"],["X","O","X"],[mediumCoderpad#graphs#implementation
- Pacific Atlantic Water FlowWrite `pacific_atlantic(heights)` returning every cell from which water can reach both oceans. Water flows to a neighbour of equal or lower height. The Pacific touches the top and left edges, the AtlamediumCoderpad#graphs#implementation
- Course ScheduleWrite `can_finish(num_courses, prerequisites)` returning `True` when every course can be taken. Each pair `[a, b]` means b must be taken before a. This is "does this directed graph have a cycle." A smediumCoderpad#graphs#implementation
- Course Schedule IIWrite `find_order(num_courses, prerequisites)` returning any valid order in which every course can be taken, or `[]` when no order exists. Same graph as Course Schedule, but now you emit the order. WmediumCoderpad#graphs#implementation
- Graph Valid TreeWrite `valid_tree(n, edges)` returning `True` when the undirected graph on `n` nodes is a tree: connected and acyclic. valid_tree(5, [[0,1],[0,2],[0,3],[1,4]]) -> True Two conditions, and bothmediumCoderpad#graphs#implementation
- Network Delay TimeWrite `network_delay_time(times, n, k)` where each `[u, v, w]` is a directed edge with delay `w`, nodes are `1..n`, and the signal starts at `k`. Return the time for all nodes to receive it, or `-1` imediumCoderpad#advanced-graphs#implementation
- Cheapest Flights Within K StopsWrite `find_cheapest_price(n, flights, src, dst, k)` returning the cheapest price from `src` to `dst` using at most `k` stops, or `-1`. n=3, flights=[[0,1,100],[1,2,100],[0,2,500]], src=0, dst=2,mediumCoderpad#advanced-graphs#implementation
- Alien DictionaryWrite `alien_order(words)` returning a letter order consistent with the given sorted word list, or `""` if none exists. Any valid order is accepted. ["wrt","wrf","er","ett","rftt"] -> "wertf" hardCoderpad#advanced-graphs#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
- House RobberWrite `rob(nums)` returning the largest sum obtainable from a list with no two chosen elements adjacent. rob([2,7,9,3,1]) -> 12 (2 + 9 + 1) At each house you either take it and add the best mediumCoderpad#dp-1d#implementation
- House Robber IIWrite `rob_circular(nums)` with the same rule as House Robber, except the first and last houses are adjacent. rob_circular([2,3,2]) -> 3 (cannot take both 2s) The circle only forbids one commediumCoderpad#dp-1d#implementation
- Longest Palindromic SubstringWrite `longest_palindrome(s)` returning the longest palindromic substring. Any one will do if several tie. longest_palindrome("babad") -> "bab" or "aba" longest_palindrome("cbbd") -> "bbmediumCoderpad#dp-1d#implementation
- Coin ChangeWrite `coin_change(coins, amount)` returning the fewest coins summing to the amount, or `-1` if impossible. Coins may be reused freely. coin_change([1,2,5], 11) -> 3 (5 + 5 + 1) Greedy — alwmediumCoderpad#dp-1d#implementation
- Longest Increasing SubsequenceWrite `length_of_lis(nums)` returning the length of the longest strictly increasing subsequence. Elements need not be contiguous. length_of_lis([10,9,2,5,3,7,101,18]) -> 4 (2,3,7,101) The O(mediumCoderpad#dp-1d#implementation
- Word BreakWrite `word_break(s, word_dict)` returning `True` when the string can be split into a sequence of dictionary words. Words may be reused. word_break("leetcode", ["leet","code"]) -> True Greedy mediumCoderpad#dp-1d#implementation
- Maximum Product SubarrayWrite `max_product(nums)` returning the largest product of any contiguous non-empty subarray. max_product([2,3,-2,4]) -> 6 max_product([-2,0,-1]) -> 0 Kadane on sums does not transfermediumCoderpad#dp-1d#implementation
- Unique PathsWrite `unique_paths(m, n)` counting the routes from the top-left to the bottom-right of an m x n grid moving only right or down. unique_paths(3, 7) -> 28 Each cell is the sum of the cell abovemediumCoderpad#dp-2d#implementation
- Longest Common SubsequenceWrite `longest_common_subsequence(a, b)` returning the length of the longest subsequence present in both strings. Subsequences need not be contiguous. longest_common_subsequence("abcde", "ace") mediumCoderpad#dp-2d#implementation
- Best Time to Buy and Sell Stock with CooldownWrite `max_profit_cooldown(prices)` returning the maximum profit with unlimited transactions, except that you may not buy on the day after you sell. max_profit_cooldown([1,2,3,0,2]) -> 3 (buymediumCoderpad#dp-2d#implementation
- Target SumWrite `find_target_sum_ways(nums, target)` counting the ways to put a `+` or `-` in front of each number so the expression equals the target. find_target_sum_ways([1,1,1,1,1], 3) -> 5 Brute fomediumCoderpad#dp-2d#implementation
- Edit DistanceWrite `min_distance(a, b)` returning the fewest single-character insertions, deletions or replacements that turn `a` into `b`. min_distance("horse", "ros") -> 3 On a match, carry the diagonal mediumCoderpad#dp-2d#implementation
- Maximum SubarrayWrite `max_subarray(nums)` returning the largest sum of any contiguous non-empty subarray. max_subarray([-2,1,-3,4,-1,2,1,-5,4]) -> 6 (4,-1,2,1) Kadane in one line of reasoning: the best submediumCoderpad#greedy#implementation
- Jump GameWrite `can_jump(nums)` where each value is the maximum jump length from that index. Return `True` if the last index is reachable from index 0. can_jump([2,3,1,1,4]) -> True can_jump([3,2,1,mediumCoderpad#greedy#implementation
- Jump Game IIWrite `min_jumps(nums)` returning the fewest jumps to reach the last index. The last index is always reachable. min_jumps([2,3,1,1,4]) -> 2 Think of it as BFS over ranges: everything reachablemediumCoderpad#greedy#implementation
- Gas StationWrite `can_complete_circuit(gas, cost)` returning the starting index from which you can drive the whole circle, or `-1`. You start with an empty tank. gas = [1,2,3,4,5], cost = [3,4,5,1,2] -> 3mediumCoderpad#greedy#implementation
- Insert IntervalWrite `insert_interval(intervals, new_interval)` inserting into a list of non-overlapping intervals sorted by start, merging where necessary, and returning the result sorted. insert([[1,3],[6,9]]mediumCoderpad#implementation#intervals
- Merge IntervalsWrite `merge_intervals(intervals)` merging all overlapping intervals and returning the result sorted by start. [[1,3],[2,6],[8,10],[15,18]] -> [[1,6],[8,10],[15,18]] Sort by start, then walk: mediumCoderpad#implementation#intervals
- Non-overlapping IntervalsWrite `erase_overlap_intervals(intervals)` returning the minimum number of intervals to remove so the rest do not overlap. Intervals that merely touch do not overlap. [[1,2],[2,3],[3,4],[1,3]] -mediumCoderpad#implementation#intervals
- Meeting Rooms IIWrite `min_meeting_rooms(intervals)` returning the fewest rooms needed so no two overlapping meetings share one. A meeting ending exactly when another starts can reuse the room. [[0,30],[5,10],[1mediumCoderpad#implementation#intervals
- 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
- 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
- Sum of Two IntegersWrite `get_sum(a, b)` returning `a + b` without using `+` or `-`. Inputs may be negative and fit in 32 bits. XOR gives the addition with every carry dropped; `(a & b) << 1` gives exactly those carriemediumCoderpad#bit-math#implementation