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 →
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 →
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 →
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 →
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 →
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 →
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 →
Find all unique triplets summing to zero. Sort array then fix one element and use two pointers. Full O(n²) solution in C, C++, Java, JavaScript and Python.
March 19, 2026 Read →
Compute product of all elements except self without division. O(n) two-pass prefix/suffix approach with O(1) extra space.
March 19, 2026 Read →
Merge all overlapping intervals. Sort by start, then merge greedily in one pass. O(n log n) time.
March 19, 2026 Read →
Return all elements of an m×n matrix in spiral order. Use boundary shrinking or direction array. O(m*n) time O(1) space.
March 19, 2026 Read →
Group strings that are anagrams of each other. Use sorted string as HashMap key. O(n*k*log k) time. Full solutions in 5 languages.
March 19, 2026 Read →
Find length of longest substring without repeating characters. Optimal O(n) sliding window with HashMap tracking last seen positions.
March 19, 2026 Read →
Search a target in a rotated sorted array with no duplicates. Modified binary search identifies which half is sorted, then checks the target range. O(log n) time.
March 19, 2026 Read →
Determine if you can reach the last index. Greedy: track maximum reachable index. If current position exceeds max reach, return false. O(n) O(1).
March 19, 2026 Read →
Rotate array right by k steps. Triple reverse trick: reverse whole, reverse first k, reverse rest. O(n) time O(1) space.
March 19, 2026 Read →
Find k most frequent elements. Approach 1: min-heap O(n log k). Approach 2: bucket sort O(n). Full 5-language solutions.
March 19, 2026 Read →
Find the maximum product of a contiguous subarray. Track both min and max at each position (negative * negative = positive). O(n) time O(1) space.
March 19, 2026 Read →
Find the one duplicate in [1..n] without modifying the array using Floyd's tortoise-and-hare cycle detection.
March 19, 2026 Read →
Insert a new interval into a sorted non-overlapping list and merge any overlaps in a single sweep.
March 19, 2026 Read →
Find all unique combinations that sum to a target, using backtracking with candidate reuse allowed.
March 19, 2026 Read →
Generate the power set of distinct integers using backtracking or bitmask enumeration.
March 19, 2026 Read →
Find the smallest contiguous subarray with sum >= target using the shrinkable sliding window technique.
March 19, 2026 Read →
Find all integers that appear twice using index-sign-marking trick in O(n) time and O(1) extra space.
March 19, 2026 Read →
Decode a run-length-encoded string like "3[a2[bc]]" = "abcbcabcbcabcbc" using a stack for nested brackets.
March 19, 2026 Read →
Find all unique combinations that sum to target where each number may be used once, skipping duplicates at each recursion level.
March 19, 2026 Read →
Search for a word in a 2D grid using DFS backtracking with in-place visited marking.
March 19, 2026 Read →
Determine if there exists an increasing subsequence of length 3 using two greedy variables in O(n) time O(1) space.
March 19, 2026 Read →
Find all unique quadruplets summing to target by extending the 3Sum pattern with an outer loop and duplicate skipping.
March 19, 2026 Read →
Find minimum number of jumps to reach the last index using greedy BFS-style level tracking.
March 19, 2026 Read →
Determine the unique starting gas station for a circular route using a greedy one-pass algorithm.
March 19, 2026 Read →
Find how many days until a warmer temperature for each day using a monotonic decreasing stack.
March 19, 2026 Read →
Find the longest consecutive integer sequence in O(n) using a HashSet and only extending sequences from their start.
March 19, 2026 Read →
Partition a string into the maximum number of parts where each letter appears in at most one part, using last occurrence mapping.
March 19, 2026 Read →
Calculate minimum CPU intervals for tasks with cooldown using a greedy formula based on the most frequent task count.
March 19, 2026 Read →
Find the minimum arrows needed to burst all balloons arranged as intervals using a greedy sort-by-end approach.
March 19, 2026 Read →
Find the missing number in [0..n] using the Gauss sum formula or XOR in O(n) time O(1) space.
March 19, 2026 Read →
Find all elements appearing more than n/3 times using Extended Boyer-Moore Voting with two candidate trackers.
March 19, 2026 Read →
Compress a sorted unique integer array into the smallest sorted list of range coverage strings.
March 19, 2026 Read →
Distribute minimum candies so each child with higher rating than neighbors gets more, using left-to-right then right-to-left passes.
March 19, 2026 Read →
Find the minimum total moves to make all array elements equal by targeting the median value.
March 19, 2026 Read →
Find the longest nested set S(k) in a permutation array by tracing cycles with visited marking in O(n) time.
March 19, 2026 Read →
Generate all unique subsets from an array with duplicates by sorting and skipping repeated elements at each recursion level.
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 →
Calculate trapped rain water using inward two pointers that track left-max and right-max, replacing the classic O(n) space approach.
March 19, 2026 Read →
Find the maximum in every sliding window of size k in O(n) using a monotonic decreasing deque.
March 19, 2026 Read →
Find the smallest missing positive integer in O(n) time O(1) space using in-place cyclic sort to place each number at its correct index.
March 19, 2026 Read →
Find the largest rectangle in a histogram in O(n) using a monotonic increasing stack that computes area when a shorter bar is encountered.
March 19, 2026 Read →
Find the minimum window in s that contains all characters of t using a shrinkable sliding window with a character frequency counter.
March 19, 2026 Read →
Count elements smaller than each element to its right using a modified merge sort that counts inversions during the merge step.
March 19, 2026 Read →
Find the median of two sorted arrays in O(log(min(m,n))) by binary searching for the correct partition point.
March 19, 2026 Read →
Find the largest rectangle of 1s in a binary matrix by treating each row as a histogram and applying the Largest Rectangle in Histogram algorithm.
March 19, 2026 Read →
Count pairs (i,j) where i<j and nums[i]>2*nums[j] using modified merge sort to count cross-half pairs before merging.
March 19, 2026 Read →
Minimize the largest sum among m subarrays by binary searching on the answer and greedy checking feasibility.
March 19, 2026 Read →
Find the shortest subarray with sum >= K using a monotonic deque on prefix sums, handling negative numbers correctly.
March 19, 2026 Read →
Find the minimum refueling stops to reach target by greedily picking the largest fuel station passed so far whenever we run out.
March 19, 2026 Read →
Find the longest subarray of 1s after deleting exactly one element using a sliding window that tracks the count of zeros.
March 19, 2026 Read →
Find the maximum number of points on the same line using a slope-as-fraction HashMap for each anchor point.
March 19, 2026 Read →
Find the longest valid parentheses substring using a stack that tracks the last unmatched index as a base.
March 19, 2026 Read →
Find the shortest subarray that when sorted makes the whole array sorted, using a single linear scan tracking violated boundaries.
March 19, 2026 Read →
Count subarrays where max element is in [L,R] using a clever counting formula with two linear scans.
March 19, 2026 Read →
Count subarrays with exactly K distinct integers using the formula: atMost(K) - atMost(K-1).
March 19, 2026 Read →
Find the minimum rotations to make all tops or bottoms equal by checking if a target value (from first domino) can unify the entire row.
March 19, 2026 Read →
Find the longest substring that appears at least twice using binary search on length and Rabin-Karp rolling hash for O(n log n) average time.
March 19, 2026 Read →
Design a stack that pops the most frequent element (breaking ties by recency) using frequency and group-stacks mapping.
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 →
Count how many stones are jewels by storing jewel types in a HashSet and checking each stone.
March 19, 2026 Read →
Group strings that are anagrams together by using their sorted form as a HashMap key.
March 19, 2026 Read →
Find the k most frequent elements in O(n) using bucket sort by frequency instead of a heap.
March 19, 2026 Read →
Design a Least Recently Used cache with O(1) get and put operations using a HashMap combined with a doubly linked list.
March 19, 2026 Read →
Count subarrays with sum exactly k using prefix sums stored in a HashMap to find valid starting positions in O(n).
March 19, 2026 Read →
Check if a continuous subarray of length >= 2 sums to a multiple of k using prefix sum modulo k with a HashMap.
March 19, 2026 Read →
Find the longest consecutive integer sequence in O(n) by using a HashSet and only starting sequences from their minimum element.
March 19, 2026 Read →
Design a set with O(1) insert, delete, and getRandom using a dynamic array combined with a HashMap for index tracking.
March 19, 2026 Read →
Find all starting indices of anagram substrings by using a fixed window with character frequency comparison.
March 19, 2026 Read →
Implement weighted random selection by building a prefix sum array and using binary search to find the sampled index.
March 19, 2026 Read →
Find the vertical line that crosses the fewest bricks by counting the most frequent gap position using a HashMap.
March 19, 2026 Read →
Remove all occurrences of val in-place using a write pointer pattern, returning the new length.
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 →
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 longest substring without duplicate characters using a HashSet-backed shrinkable sliding window.
March 19, 2026 Read →
Check if any permutation of s1 is a substring of s2 using a fixed-size sliding window with character frequency comparison.
March 19, 2026 Read →
Find the smallest subarray with sum >= target using a variable sliding window that shrinks from the left when the condition is met.
March 19, 2026 Read →
Maximize water trapped between two vertical lines using inward two pointers that always move the shorter line inward.
March 19, 2026 Read →
Find minimum boats to save everyone where each boat carries at most 2 people with total weight <= limit, using sort + greedy two pointers.
March 19, 2026 Read →
Find all unique triplets summing to zero by sorting and using two pointers for each fixed element with careful duplicate skipping.
March 19, 2026 Read →
Find two numbers summing to target in a 1-indexed sorted array using inward two pointers in O(n) time O(1) space.
March 19, 2026 Read →
Maximize card points taken from both ends of an array by finding the minimum-sum subarray of size n-k in the middle.
March 19, 2026 Read →
Find minimum operations to reduce X to zero from either end by finding the longest middle subarray with sum = total-X.
March 19, 2026 Read →
Find the maximum number of vowels in any substring of length k using a fixed sliding window with vowel count.
March 19, 2026 Read →
Find minimum swaps to group all 1s together in a circular binary array using a fixed-size sliding window equal to the count of 1s.
March 19, 2026 Read →
Maximize customer satisfaction by finding the best k-minute window for the bookstore owner to stay non-grumpy.
March 19, 2026 Read →
Count substrings containing at least one a, b, and c using the last-seen indices shortcut for O(n) time.
March 19, 2026 Read →
Count subarrays with sum divisible by k using prefix sum modulo k and a frequency map of remainders.
March 19, 2026 Read →
Sort only the vowels in a string while keeping consonants in place by extracting vowels, sorting, then reinserting.
March 19, 2026 Read →
Find the median of each sliding window of size k using two heaps (max-heap for lower half, min-heap for upper half) with lazy deletion.
March 19, 2026 Read →
Find the smallest window in s containing all characters of t using a have/need counter to track when the window is valid.
March 19, 2026 Read →
Find the maximum in every sliding window of size k in O(n) using a monotonic decreasing deque of indices.
March 19, 2026 Read →
Find the shortest subarray with sum >= k, handling negative numbers correctly using a monotonic deque on prefix sums.
March 19, 2026 Read →
Check if a string can become a palindrome by deleting at most one character using recursive two-pointer palindrome checking.
March 19, 2026 Read →
Calculate trapped rainwater using optimal two-pointer approach that tracks left and right maximums without extra space.
March 19, 2026 Read →
Full company-specific mock sessions. Each simulation replicates the actual interview format, problem difficulty distribution, and evaluation criteria of Google, Meta, and Amazon.
February 20, 2025 Read →
Map Amazon's 16 Leadership Principles to coding interview behaviors. Know which LP each behavioral question targets, and how to weave LP language naturally into technical answers.
February 20, 2025 Read →
Strategic guide to company-specific DSA preparation: Google's focus on graphs and DP, Meta's emphasis on arrays and trees, Amazon's leadership principles alignment with system design and BFS.
February 15, 2025 Read →
Count islands after each addLand operation using incremental Union-Find. Each new land cell potentially merges with up to 4 neighbors — classic Amazon system-at-scale problem.
February 15, 2025 Read →
Design a stream that always returns the kth largest element after each add. Uses a min-heap of size k — the top is always the kth largest.
February 15, 2025 Read →
Find the minimum intervals to complete all tasks given cooldown n. Greedy with max-heap: always execute most frequent available task, idle only when forced.
February 15, 2025 Read →
Merge k sorted linked lists into one sorted list using a min-heap. O(n log k) time by always extracting the current minimum across all list heads.
February 15, 2025 Read →
Find the k most frequent elements using a max-heap or bucket sort. O(n) bucket sort approach using frequency as bucket index — faster than O(n log n) heap.
February 15, 2025 Read →
Comprehensive coverage of Two Sum, Two Sum II (sorted), 3Sum, and 4Sum. Amazon frequently tests these variants to gauge understanding of hashmap vs two-pointer trade-offs.
February 15, 2025 Read →
Find the median of two sorted arrays in O(log(min(m,n))) time using binary search on partition points. A classic hard problem testing deep binary search understanding.
February 15, 2025 Read →
Complete recap of all 24 company-tagged problems with pattern classification, company attribution, and key insights. Use as a final review checklist before company-specific interviews.
February 15, 2025 Read →