Two Sum is the most asked interview problem at Google, Amazon and Meta. Learn every approach from O(n²) brute force to O(n) HashMap with C, C++, Java, JavaScript and Python solutions.
March 19, 2026 Read →
The classic stock problem asked at Amazon, Google and Microsoft. Learn the O(n) greedy "min so far" approach with complete solutions in C, C++, Java, JavaScript and Python, plus extensions to Stock II, III and IV.
March 19, 2026 Read →
Solve Contains Duplicate in O(n) time using a HashSet. Full solutions in C, C++, Java, JavaScript and Python with sorting alternative and follow-up questions asked at Amazon interviews.
March 19, 2026 Read →
Kadane's Algorithm is a must-know pattern for FAANG interviews. Solve Maximum Subarray in O(n) time with full solutions in C, C++, Java, JavaScript and Python, plus divide-and-conquer O(n log n) alternative.
March 19, 2026 Read →
Move all zeroes to end while maintaining relative order of non-zero elements. Optimal O(n) two-pointer solution with minimal writes. Full C, C++, Java, JavaScript and Python code.
March 19, 2026 Read →
Increment a large integer represented as an array by one. Learn the carry propagation pattern with O(n) solutions in C, C++, Java, JavaScript and Python.
March 19, 2026 Read →
Merge two sorted arrays in-place by filling from the end. The classic 3-pointer technique asked at Meta and Microsoft. Full solutions in C, C++, Java, JavaScript and Python.
March 19, 2026 Read →
Remove duplicates from a sorted array in-place using the write pointer pattern. O(n) time, O(1) space. Full solutions in C, C++, Java, JavaScript, Python with follow-up for allowing k duplicates.
March 19, 2026 Read →
Find the element that appears once while every other appears twice. The XOR bit trick gives O(n) time and O(1) space. Full solutions in C, C++, Java, JavaScript, Python plus Single Number II and III extensions.
March 19, 2026 Read →
Find the intersection of two integer arrays including duplicates. Each element appears as many times as it shows in both arrays.
March 19, 2026 Read →
Generate numRows rows of Pascal's triangle. Each interior element is the sum of the two elements above it.
March 19, 2026 Read →
Check if two strings are anagrams — same characters with same frequencies. Two O(n) approaches: 26-int array for lowercase, HashMap for Unicode.
March 19, 2026 Read →
Reverse a character array in-place using two pointers. O(n) time, O(1) space. The fundamental two-pointer swap pattern.
March 19, 2026 Read →
Find the index of the first non-repeating character in a string. Two-pass O(n) solution with a 26-array or HashMap.
March 19, 2026 Read →
Determine if a string is a palindrome considering only alphanumeric characters and ignoring cases. Two pointer O(n) O(1) solution with all 5 language implementations.
March 19, 2026 Read →
Find the longest common prefix string among an array of strings. Covers vertical scan O(n*m), horizontal scan, binary search, and Trie approaches with all 5 language solutions.
March 19, 2026 Read →
Count the number of prime numbers strictly less than n. Master the Sieve of Eratosthenes — one of the most elegant algorithms in CS — with full code in C, C++, Java, JavaScript and Python.
March 19, 2026 Read →
Find the missing number in [0,n]. Two elegant O(n) O(1) solutions: Gauss formula and XOR trick. Full solutions in C, C++, Java, JavaScript and Python.
March 19, 2026 Read →
Find the majority element that appears more than n/2 times. Boyer-Moore Voting Algorithm achieves O(n) time and O(1) space. Full C, C++, Java, JavaScript and Python solutions.
March 19, 2026 Read →
Find all integers in [1,n] missing from array of length n using O(n) time O(1) extra space via index negation.
March 19, 2026 Read →
Return the third distinct maximum or the max if fewer than 3 distinct values exist. Three-variable tracking O(n) O(1) solution.
March 19, 2026 Read →
Design a class to find the kth largest element in a data stream. Min-heap of size k: the top is always the answer. Full C++, Java, JavaScript and Python.
March 19, 2026 Read →
Implement Fisher-Yates shuffle for uniform random permutation. Every arrangement is equally probable. O(n) time O(1) extra space.
March 19, 2026 Read →
Compute running (prefix) sum in O(n) time O(1) extra space. The prefix sum pattern is foundational for range queries, subarray problems and 2D matrices.
March 19, 2026 Read →
Compress a sorted unique integer array into the smallest sorted list of range coverage strings.
March 19, 2026 Read →
Check if string B is a rotation of A by checking if B appears in A+A using a substring search.
March 19, 2026 Read →
Implement classic binary search to find a target in a sorted array in O(log n) time.
March 19, 2026 Read →
Find the first bad version using left-boundary binary search: shrink hi to mid when version is bad.
March 19, 2026 Read →
Find where a target would be inserted in a sorted array using left-boundary binary search returning lo.
March 19, 2026 Read →
Compute integer square root using right-boundary binary search to find the largest k where k*k <= x.
March 19, 2026 Read →
Find the picked number using binary search with the guess() API that returns -1, 0, or 1.
March 19, 2026 Read →
Count negatives in a sorted matrix in O(m+n) using the staircase approach or O(m log n) with binary search per row.
March 19, 2026 Read →
Check if a number is a perfect square in O(log n) using binary search or by exploiting odd-number sum identity.
March 19, 2026 Read →
Check if any element and its double both exist in an array using a hash set or sorting with binary search.
March 19, 2026 Read →
Every element appears twice except one. XOR all numbers: duplicates cancel (a^a=0), single number remains.
March 19, 2026 Read →
Count set bits (popcount). Brian Kernighan: n & (n-1) clears the lowest set bit; count how many operations until n=0.
March 19, 2026 Read →
Count set bits for all numbers 0..n. DP: dp[i] = dp[i >> 1] + (i & 1). Remove last bit and check if it was set.
March 19, 2026 Read →
Reverse bits of a 32-bit unsigned integer. Shift result left and input right 32 times, taking last bit each time.
March 19, 2026 Read →
Find missing number in 0..n array. XOR approach: XOR all indices with all values, duplicate indices cancel. Or math: n*(n+1)/2 - sum.
March 19, 2026 Read →
Count ways to climb n stairs taking 1 or 2 steps. Classic Fibonacci DP — dp[n] = dp[n-1] + dp[n-2] with O(1) space.
March 19, 2026 Read →
Find minimum cost to reach the top of stairs. Each stair has a cost; you can take 1 or 2 steps. DP: min cost to reach each stair.
March 19, 2026 Read →
Find the contiguous subarray with the largest sum. Kadane's algorithm: either extend previous subarray or start fresh at current element.
March 19, 2026 Read →
Maximize profit from a single buy-sell. Track running minimum price; at each day profit = price - min_so_far.
March 19, 2026 Read →
Maximize children satisfied. Sort both greed and cookie sizes; greedily assign the smallest sufficient cookie to each child.
March 19, 2026 Read →
For each element in nums1, find next greater element in nums2. Monotonic stack + hashmap: process nums2, pop when greater found, store in map.
March 19, 2026 Read →
Find two indices that add to target in O(n) by storing each number in a HashMap and looking up the complement.
March 19, 2026 Read →
Check if two strings are anagrams by comparing their character frequency counts using an array or HashMap.
March 19, 2026 Read →
Check if a ransom note can be constructed from magazine letters using a character frequency map.
March 19, 2026 Read →
Check if two strings are isomorphic by maintaining bidirectional character mappings to ensure a consistent one-to-one correspondence.
March 19, 2026 Read →
Check if a string follows a given pattern using bidirectional mapping between pattern chars and words.
March 19, 2026 Read →
Determine if a number is happy by repeatedly summing digit squares and detecting cycles using a HashSet or Floyd algorithm.
March 19, 2026 Read →
Find if any two duplicate elements are within k indices of each other using a HashMap of last-seen positions.
March 19, 2026 Read →
Find characters common to all strings in a list by intersecting their frequency arrays with element-wise minimum.
March 19, 2026 Read →
Count how many stones are jewels by storing jewel types in a HashSet and checking each stone.
March 19, 2026 Read →
Check if all value frequencies are unique using two hash sets in O(n).
March 19, 2026 Read →
Maintain a min-heap of size K to track the Kth largest element as numbers are added to a stream.
March 19, 2026 Read →
Simulate stone smashing by repeatedly extracting the two heaviest stones using a max-heap.
March 19, 2026 Read →
Assign gold/silver/bronze or rank numbers to athletes based on their scores using sorted ordering.
March 19, 2026 Read →
Sort array elements by frequency ascending, breaking ties by value descending.
March 19, 2026 Read →
Find the subsequence of length k with the largest sum by selecting top k values while preserving original order.
March 19, 2026 Read →
Reverse a singly linked list iteratively with three-pointer technique and recursively with call stack.
March 19, 2026 Read →
Find the middle node of a linked list in one pass using the slow/fast pointer technique.
March 19, 2026 Read →
Detect a cycle in a linked list in O(1) space using Floyd's two-pointer tortoise and hare algorithm.
March 19, 2026 Read →
Merge two sorted linked lists into one sorted list using a dummy head node to simplify pointer management.
March 19, 2026 Read →
Check if a linked list is a palindrome by finding the middle, reversing the second half, then comparing.
March 19, 2026 Read →
Remove duplicate nodes from a sorted linked list in O(n) with a single pointer walk.
March 19, 2026 Read →
Delete a node given only access to that node by copying the next node value and skipping the next node.
March 19, 2026 Read →
Find the intersection node of two linked lists in O(n) O(1) by switching pointers at the end of each list.
March 19, 2026 Read →
Convert a linked list representing a binary number to its integer value using left-shift accumulation.
March 19, 2026 Read →
Remove all nodes with a given value from a linked list using a dummy head to handle edge cases cleanly.
March 19, 2026 Read →
Check if a string of brackets is valid by pushing open brackets and matching close brackets against the stack.
March 19, 2026 Read →
Implement a stack using one queue by rotating all elements after each push to bring the new element to the front.
March 19, 2026 Read →
Implement a queue using two stacks with amortized O(1) operations by lazily transferring from inbox to outbox.
March 19, 2026 Read →
Design a stack with O(1) getMin by maintaining a parallel min-tracking stack alongside the main stack.
March 19, 2026 Read →
Simulate a baseball scoring game using a stack to track valid scores and handle +, D, and C operations.
March 19, 2026 Read →
Compare two strings after applying backspace characters in O(1) space by scanning from right with skip counters.
March 19, 2026 Read →
Track the minimum number of operations to return to the main folder by simulating directory navigation with a depth counter.
March 19, 2026 Read →
Count ping requests within the last 3000ms using a queue that slides expired entries off the front.
March 19, 2026 Read →
Remove adjacent pairs of same letters with different cases using a stack to build the result character by character.
March 19, 2026 Read →
Find the maximum depth of a binary tree using recursive DFS (one line) or iterative BFS level counting.
March 19, 2026 Read →
Invert a binary tree by recursively swapping left and right children at every node.
March 19, 2026 Read →
Check if a binary tree is symmetric by comparing mirror subtrees with a two-pointer recursive approach.
March 19, 2026 Read →
Determine if a root-to-leaf path exists with a given sum using DFS that subtracts each node value from the target.
March 19, 2026 Read →
Check if two binary trees are identical by recursively comparing structure and node values.
March 19, 2026 Read →
Check if a binary tree is height-balanced by computing subtree heights and returning -1 early on imbalance.
March 19, 2026 Read →
Merge two binary trees by adding overlapping node values recursively, using existing nodes where possible.
March 19, 2026 Read →
Sum all BST values in [low, high] using BST property to prune entire subtrees outside the range.
March 19, 2026 Read →
Find a node with given value in a BST by navigating left or right based on the BST property.
March 19, 2026 Read →
Find second minimum value in a special binary tree where root is min and each node equals min of its children.
March 19, 2026 Read →
Build a preorder string representation of a binary tree using parentheses to show tree structure.
March 19, 2026 Read →
Determine if two nodes are cousins (same depth, different parents) using BFS to track depth and parent.
March 19, 2026 Read →
Traverse an N-ary tree in preorder and postorder using DFS with a stack or recursion.
March 19, 2026 Read →
Rearrange a BST into a right-skewed tree with no left children using in-order traversal.
March 19, 2026 Read →
Count words with given prefix. Simple trie with count at each node; reach prefix end and return count.
March 19, 2026 Read →
Check if a string is a palindrome after removing non-alphanumeric characters using inward two pointers.
March 19, 2026 Read →
Reverse an array of characters in-place using the classic two-pointer swap technique.
March 19, 2026 Read →
Return squares of a sorted array in sorted order using two pointers that compare absolute values from both ends.
March 19, 2026 Read →
Remove all occurrences of val in-place using a write pointer pattern, returning the new length.
March 19, 2026 Read →
Remove duplicates in-place from a sorted array using a write pointer that only advances on unique elements.
March 19, 2026 Read →
Merge two sorted arrays in-place from the end to avoid overwriting elements using three pointers.
March 19, 2026 Read →
Check if string s is a subsequence of t using a greedy two-pointer scan that matches characters in order.
March 19, 2026 Read →
Count days with fixed-size window sums above upper and below lower thresholds using a sliding fixed window.
March 19, 2026 Read →
Compute the running sum of a 1D array where each element is the sum of itself and all previous elements.
March 19, 2026 Read →
Find the minimum difference between the max and min of any k scores by sorting and using a fixed window of size k.
March 19, 2026 Read →
Check if an array can be split into three consecutive parts with equal sum using a greedy counting approach.
March 19, 2026 Read →
Week 1 mock session: two carefully chosen easy/medium problems designed to build communication habits. Full problem walkthrough with example think-aloud scripts.
February 20, 2025 Read →