Master every Arrays & Strings pattern asked in Google, Meta, Amazon, Apple & Microsoft interviews. Covers prefix sum, Kadane, Dutch flag, two pointers, sliding window and 100 hand-picked problems with C, C++, Java, JavaScript & Python solutions.
March 19, 2026 Read →
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 →
Master cheatsheet of all 100 Arrays & Strings problems: patterns, time/space complexity, and MAANG company tags in one place.
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 →
Find maximum consecutive ones if you can flip at most k zeros to one. Variable sliding window O(n) solution.
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 →
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 →
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 →
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 →
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 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 →
Sort an array of 0s, 1s, and 2s in-place in one pass using Dijkstra's Dutch National Flag algorithm.
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 →
Find all unique combinations that sum to a target, using backtracking with candidate reuse allowed.
March 19, 2026 Read →
Generate all permutations of distinct integers using in-place swap backtracking.
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 →
Maximize a number by making at most one swap, using a last-occurrence map to find the optimal swap greedily.
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 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 →
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 →
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 →
Rearrange nums to maximize advantage over B using a greedy strategy: assign the smallest winning card, else discard the smallest.
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 →
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 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 →
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 →
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 the k most frequent elements in O(n) using bucket sort by frequency instead of a heap.
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 →
Find the vertical line that crosses the fewest bricks by counting the most frequent gap position using a HashMap.
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 →
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 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 →
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 →
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 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 maximum consecutive ones in a binary array when you can flip at most k zeros, identical to the Max Consecutive Ones III pattern.
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 →
Count subarrays where score = sum × length is less than k using a shrinkable sliding window with running sum.
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 →
Sort an array of 0s, 1s, and 2s in one pass using the Dutch National Flag 3-pointer algorithm.
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 →
JavaScript array methods are the bread and butter of every developer. map, filter, reduce, find, flat, flatMap — knowing when to use which transforms messy loops into clean, readable code. Here's your complete, practical reference.
March 13, 2026 Read →