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 →
Master cheatsheet of all 100 Arrays & Strings problems: patterns, time/space complexity, and MAANG company tags in one place.
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 →
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 →
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 →
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 →
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 →
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 all starting indices of anagram substrings by using a fixed window with character frequency comparison.
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 →
Check if string s is a subsequence of t using a greedy two-pointer scan that matches characters in order.
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 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 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 →
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 →
Sort only the vowels in a string while keeping consonants in place by extracting vowels, sorting, then reinserting.
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 →
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 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 →
Check if a string can become a palindrome by deleting at most one character using recursive two-pointer palindrome checking.
March 19, 2026 Read →
Master advanced string algorithms: KMP failure function for O(n) pattern matching, Z-algorithm for all prefix matches, Rabin-Karp rolling hash, and suffix arrays for substring queries.
March 1, 2025 Read →
Implement KMP string search: build the failure function (LPS array) in O(m) then search in O(n). Never re-examines matched characters unlike naive search.
March 1, 2025 Read →
The Z-algorithm computes Z[i] = length of the longest substring starting at i that matches a prefix of the string. O(n) time, elegant and powerful for pattern search.
March 1, 2025 Read →
Rabin-Karp uses a rolling polynomial hash to match patterns in O(n+m) expected time. The key is updating the hash in O(1) as the window slides.
March 1, 2025 Read →
Find the longest palindromic substring in O(n) using Manacher's algorithm. Expands palindromes using a mirror trick to avoid redundant work.
March 1, 2025 Read →
Precompute polynomial prefix hashes to compare any two substrings in O(1). Enables O(n log n) LCP computation and O(n) duplicate detection.
March 1, 2025 Read →
Build a suffix array in O(n log²n) using doubling sort. Enables O(m log n) substring search, longest common substring, and number of distinct substrings.
March 1, 2025 Read →
Find the longest common substring between two strings. DP approach O(nm), binary search + rolling hash O((n+m) log(n+m)).
March 1, 2025 Read →
Core string DP patterns: edit distance (Wagner-Fischer), longest common subsequence, interleaving strings, and regular expression matching.
March 1, 2025 Read →
Group anagrams, find anagram indices, and count anagram occurrences. Three approaches: sort key O(nk log k), frequency tuple O(nk), and sliding window O(n+k).
March 1, 2025 Read →
Comprehensive palindrome problem coverage: valid palindrome check, longest palindromic substring (three methods), count palindromic substrings, and palindrome partitioning.
March 1, 2025 Read →
Word Search I and II solved with DFS backtracking. Word Search II uses a Trie to prune the search space from O(N·4^L) per word to O(N·4^L) total for all words.
March 1, 2025 Read →
Design an encode/decode scheme for a list of strings. Length-prefix encoding (4-byte header per string) is collision-proof unlike delimiter-based approaches.
March 1, 2025 Read →
Add minimum characters to the front of a string to make it a palindrome. KMP trick: concatenate s + '#' + rev(s), find the LPS value at the last position.
March 1, 2025 Read →
Count the number of distinct substrings using the suffix array and LCP array. Total substrings minus sum of LCP values gives distinct count in O(n log n).
March 1, 2025 Read →
Implement run-length encoding, string compression in-place, and decode compressed strings. Tests two-pointer technique and string manipulation.
March 1, 2025 Read →
Advanced trie applications beyond basic insert/search: binary trie for XOR maximization, palindrome pairs detection, and stream search using Aho-Corasick automaton concept.
March 1, 2025 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 →
Aho-Corasick automaton matches all patterns simultaneously in O(n+m+z) where z is the number of matches. Builds failure links on a trie for efficient multi-pattern search.
March 1, 2025 Read →
Complete recap of all 20 string algorithm problems: pattern recognition guide, algorithm selection, and complexity reference.
March 1, 2025 Read →