Interview Problems
Each problem shows a strong candidate's seven-step thinking, five progressive hints you control, a full solution analysis, and a follow-up engine that changes the requirements.
Minimum Size Subarray SumIntermediate
Given an array of **positive** integers `nums` and a positive integer `k`, return the length of the shortest contiguous subarray whose sum is greater than or equal to `k`. If no such subarray exists, return `0`. The subarray must be contiguous — you may not skip elements.
Arrays
Two SumBeginner
Given an array of integers `nums` and an integer `target`, return the indices of the two distinct elements whose values add up to `target`. You may assume exactly one valid answer exists, and you may not use the same element twice. The indices may be returned in any order.
Arrays · Hashing
Longest Substring Without Repeating CharactersIntermediate
Given a string `s`, return the length of the longest substring that contains no repeated characters. A substring is contiguous; characters are compared exactly (case-sensitive).
Strings · Hashing
Kth Largest Element in an ArrayIntermediate
Given an integer array `nums` and an integer `k`, return the `k`-th largest element in the array in sorted order (not the `k`-th distinct element). For example, in `[3,2,1,5,6,4]` with `k = 2` the answer is `5`. Try to do better than sorting the whole array.
Heaps · Arrays
Daily TemperaturesIntermediate
Given an array `temperatures` where `temperatures[i]` is the temperature on day `i`, return an array `answer` where `answer[i]` is the number of days you have to wait after day `i` to get a strictly warmer temperature. If there is no future day with a warmer temperature, `answer[i]` should be `0`.
Stacks & Queues · Arrays
Course ScheduleIntermediate
There are `numCourses` courses labelled `0 … numCourses - 1`. You are given a list `prerequisites` where `[a, b]` means you must take course `b` before course `a`. Return `true` if it is possible to finish all courses, and `false` otherwise.
Graphs
Network Delay TimeAdvanced
You are given a network of `n` nodes labelled `1 … n` and a list of directed edges `times[i] = [u, v, w]` meaning a signal sent from `u` reaches `v` after `w` units of time. A signal is sent from node `k`. Return the minimum time for **all** nodes to receive the signal, or `-1` if it is impossible for every node to receive it.
Graphs · Heaps
Number of IslandsIntermediate
Given an `m × n` grid of characters where `'1'` represents land and `'0'` represents water, return the number of islands. An island is a maximal group of land cells connected horizontally or vertically (not diagonally). You may assume the grid is surrounded by water.
Graphs · Arrays
Coin ChangeIntermediate
You are given an array `coins` of distinct positive coin denominations and an integer `amount`. Return the fewest number of coins needed to make up exactly `amount`. You have an unlimited supply of each coin. If the amount cannot be made, return `-1`.
Dynamic Programming
Search in Rotated Sorted ArrayIntermediate
An ascending sorted array of distinct integers has been rotated at some unknown pivot, so `[0,1,2,4,5,6,7]` may become `[4,5,6,7,0,1,2]`. Given the rotated array `nums` and a `target`, return the index of `target` or `-1` if it is not present. Your algorithm must run in `O(log n)` time.
Arrays
Merge IntervalsIntermediate
Given an array of intervals where `intervals[i] = [start_i, end_i]`, merge all overlapping intervals and return an array of the non-overlapping intervals that cover all the intervals in the input. Two intervals that merely touch (one ends where the other starts) are considered overlapping.
Arrays · Greedy
Word SearchAdvanced
Given an `m × n` grid of characters `board` and a string `word`, return `true` if `word` can be constructed from letters of sequentially adjacent cells. Adjacent cells are horizontal or vertical neighbours, and the same cell may not be used more than once in a single word.
Backtracking · Arrays
Subarray Sum Equals KIntermediate
Given an array of integers `nums` (which may include negatives and zeros) and an integer `k`, return the total number of contiguous subarrays whose sum equals exactly `k`. Subarrays are counted by position, so identical values at different positions count separately.
Arrays · Hashing
Top K Frequent ElementsIntermediate
Given an integer array `nums` and an integer `k`, return the `k` most frequent elements. The answer is guaranteed to be unique (no ties at the `k`-th position), and it may be returned in any order. Aim for a solution better than `O(n log n)`.
Hashing · Heaps
Implement Trie (Prefix Tree)Intermediate
Design a data structure `Trie` supporting three operations: `insert(word)` adds a word, `search(word)` returns `true` if the exact word was previously inserted, and `startsWith(prefix)` returns `true` if any inserted word begins with `prefix`. All strings consist of lowercase English letters. The structure will receive up to `3·10^4` mixed operations.
Trees · Strings · Design