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 →
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 →
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 →
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 maximum consecutive ones if you can flip at most k zeros to one. Variable sliding window O(n) solution.
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 →
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 →
Find two lines that together with the x-axis form a container holding the most water. Greedy two-pointer O(n) — never check a pair that can't be optimal.
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 →
Count subarrays summing to k. Classic prefix sum + HashMap trick: if prefix[j]-prefix[i]=k then prefix[i]=prefix[j]-k. O(n) time.
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 →
Find the minimum element in a rotated sorted array with no duplicates. Binary search: the minimum is in the unsorted half. O(log 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 →
Rotate an n×n matrix 90 degrees clockwise in-place. Trick: transpose (swap i,j with j,i) then reverse each row. O(n²) time O(1) space.
March 19, 2026 Read →
Find the lexicographically next permutation in-place using a two-pass scan from the right.
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 the minimum number of intervals to remove so the rest are non-overlapping, using a greedy earliest-end-time strategy.
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 →
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 →
Find the minimum arrows needed to burst all balloons arranged as intervals using a greedy sort-by-end approach.
March 19, 2026 Read →
Find a peak element in O(log n) by binary searching on the slope direction — always move toward the higher neighbor.
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 →
Rearrange an array so nums[0] < nums[1] > nums[2] < nums[3]... using virtual index mapping and nth_element for O(n) time.
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 →
Rearrange nums to maximize advantage over B using a greedy strategy: assign the smallest winning card, else discard the smallest.
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 →
Find the minimum times A must repeat so that B is a substring, using a tight bound on the number of repeats needed.
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 →
Count the number of range sums that lie in [lower, upper] using a merge sort approach on prefix sums.
March 19, 2026 Read →
Find three non-overlapping subarrays of length k with maximum sum using sliding window sums and left/right best index arrays.
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 with exactly K distinct integers using the formula: atMost(K) - atMost(K-1).
March 19, 2026 Read →
Reconstruct the stamp sequence in reverse by greedily finding where the stamp can overwrite current characters in the target string.
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 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 →
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 →
Find all groups of duplicate files by parsing path strings and grouping files by their content using a HashMap.
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 →
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 →
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 →
Find the maximum number of consecutive 1s achievable by flipping at most k zeros, using a variable sliding window.
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 →
Find the longest substring without duplicate characters using a HashSet-backed shrinkable sliding window.
March 19, 2026 Read →
Find the longest substring with at most k character replacements by tracking the maximum frequency char in the 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 maximum fruits you can collect starting from any tree with two baskets (at most 2 distinct fruit types) using a sliding window.
March 19, 2026 Read →
Find the maximum sum of a subarray with all unique elements using a sliding window backed by a HashSet.
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 →
Count tuples (i,j,k,l) where nums1[i]+nums2[j]+nums3[k]+nums4[l]=0 by hashing all pairs from first two arrays.
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 →
Count contiguous subarrays with product < k using a sliding window that divides from the left when product exceeds the limit.
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 →
Count subarrays with exactly k odd numbers using the at-most(k) minus at-most(k-1) sliding window formula.
March 19, 2026 Read →
Count binary subarrays with exactly the given sum using prefix sum with HashMap or the atMost(k)-atMost(k-1) trick.
March 19, 2026 Read →
Find the maximum frequency of any element after at most k increments by sorting and using a sliding window with a running sum.
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 longest mountain subarray (strictly increasing then decreasing) using two separate forward scans for up and down slopes.
March 19, 2026 Read →
Find the longest turbulent subarray where comparisons alternate between > and < using two-pointer direction tracking.
March 19, 2026 Read →
Count subarrays with exactly K distinct integers using the mathematical trick: exactly(K) = atMost(K) - atMost(K-1).
March 19, 2026 Read →
Find the minimum length substring to replace so that a string of QWER has equal frequencies, using a shrinkable two-pointer approach.
March 19, 2026 Read →
Find minimum character flips to make a binary string alternating by applying a fixed circular sliding window of size n.
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 →
Find minimum minutes to collect at least k of each character from ends by finding the longest middle window that can be excluded.
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 →
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 →
Find the maximum length substring you can transform from s to t within a given cost budget using a sliding window on character change costs.
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 →
Find k closest integers to x in a sorted array using binary search to locate the optimal left boundary of the window.
March 19, 2026 Read →
Count subarrays where min=minK and max=maxK using a single pass tracking the last invalid position and last positions of minK and maxK.
March 19, 2026 Read →
Find the minimum window in s that contains t as a subsequence by using a forward pass to find a valid window then backward pass to minimize it.
March 19, 2026 Read →
Count subarrays where the median is exactly k by converting the problem to counting balanced prefix sequences around k.
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 all starting indices of substrings that are concatenations of all given words using a sliding window for each possible word-aligned start.
March 19, 2026 Read →
Find the minimum number of consecutive cards that contain a matching pair using a HashMap tracking last seen positions.
March 19, 2026 Read →
Count subarrays where score = sum × length is less than k using a shrinkable sliding window with running sum.
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 →
Find the longest substring containing at most 2 distinct characters using a variable sliding window with a character count map.
March 19, 2026 Read →
Find the longest contiguous subarray of 1s after deleting exactly one element using a sliding window allowing at most one zero.
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 →
Calculate trapped rainwater using optimal two-pointer approach that tracks left and right maximums without extra space.
March 19, 2026 Read →
High-frequency string problems from Meta and Google interviews: valid parentheses, longest substring without repeating characters, zigzag conversion, and string to integer.
March 1, 2025 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 →
Google's interview process: Googleyness criteria, coding expectations, and how to prepare for the unique 'How would you improve Google Maps?' style questions.
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 →
Search for a target in a matrix where each row and column is sorted. O(m+n) solution using top-right corner elimination — a classic Google interview problem.
February 15, 2025 Read →
Derive character ordering from a sorted alien dictionary using topological sort. Build a directed graph from adjacent word comparisons and apply Kahn's BFS algorithm.
February 15, 2025 Read →
Find the maximum in every sliding window of size k using a monotonic decreasing deque. O(n) solution that Google uses to test understanding of amortised data structures.
February 15, 2025 Read →
Find the smallest substring of s containing all characters of t using an expanding/contracting two-pointer window with frequency counting. O(n) time.
February 15, 2025 Read →
Find the longest substring with at most k distinct characters using a sliding window with a character frequency map. O(n) time.
February 15, 2025 Read →
Count the number of inversions in an array (pairs where i < j but arr[i] > arr[j]) using modified merge sort in O(n log n). Google uses this to test deep algorithm understanding.
February 15, 2025 Read →
Return all ways to segment a string into dictionary words. Combines DP validity check with DFS+memo backtracking to avoid TLE on valid inputs.
February 15, 2025 Read →
Calculate how much water can be trapped in a 3D height matrix. Uses a min-heap BFS starting from the boundary, always processing the lowest border cell to determine water trapped inside.
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 →