LC 28 Find the Index of the First Occurrence in a String is the canonical KMP problem at Google, Meta, and Amazon. Build the failure function in O(m), search in O(n), and never re-examine a matched character again.
A complete tour of the seven advanced graph patterns FAANG interviewers test most: Kruskal and Prim MST, Tarjan SCC, bridges and articulation points, Floyd-Warshall all-pairs shortest path, Bellman-Ford with negative cycles, and A-star heuristic search. One pattern recognition guide that turns every advanced graph problem into a routine implementation.
Master Tarjan's SCC algorithm: a single DFS pass with discovery times, low-link values, and an explicit stack to identify all strongly connected components in O(V + E). The interview gold standard for directed graph decomposition, asked at Google, Meta, and Uber.
Use Tarjan's low-link technique to find every bridge (critical edge) and articulation point (cut vertex) in an undirected graph in O(V + E). The interview pattern behind LeetCode 1192 Critical Connections, asked at Google, Meta, and Amazon.
Master Bellman-Ford: relax every edge V-1 times to compute single-source shortest paths even with negative edges, and detect negative cycles in one extra pass. The algorithm behind LeetCode 787 Cheapest Flights Within K Stops, asked at Google, Amazon, and Meta.
Master advanced Dijkstra: state augmentation, K-stop limits, two-cost optimisation, k-th shortest paths, and modified relaxation. The interview pattern behind LeetCode 787, 1928, and 1976, asked at Google, Amazon, and Meta.
Master bipartite checking and graph coloring: a single BFS or DFS pass that 2-colors a graph and proves it is bipartite, or finds an odd cycle. The pattern behind LeetCode 785 Is Graph Bipartite and LeetCode 886 Possible Bipartition, asked at Google, Meta, and Amazon.
Master LeetCode 1584 Min Cost to Connect All Points: model the n^2 implicit edges as a complete graph, then run Prim's MST in O(n^2) without ever materialising the edge list. A FAANG-favourite interview question at Amazon, Google, and Meta that tests whether you can spot a Minimum Spanning Tree behind a geometry prompt.
Solve the bottleneck shortest path problem: find a route from source to destination that minimises the maximum edge weight on the path. Combines binary search on the answer with BFS connectivity checks in O((V+E) log W) — a FAANG interview pattern asked at Google and Amazon, and the foundation behind LeetCode 1102 Path With Maximum Minimum Value.
Master LeetCode 1976 Number of Ways to Arrive at Destination: extend Dijkstra to count the number of distinct shortest paths simultaneously, returning the count modulo 10^9+7. A FAANG-favourite shortest-path counting interview question asked at Google, Amazon, and Meta.
Master LeetCode 1192 Critical Connections in a Network: a textbook Tarjan bridge-finding algorithm using DFS with discovery times and low-link values to detect every edge whose removal disconnects the graph. A FAANG hard graph interview classic at Google, Amazon, and Meta.
Master LeetCode 332 Reconstruct Itinerary using Hierholzer's algorithm: a single DFS that traverses every edge exactly once and assembles an Eulerian path via post-order insertion. A FAANG hard interview classic asked at Google, Meta, and Amazon, and the foundational pattern for de Bruijn sequences and DNA fragment assembly.
Master LeetCode 778 Swim in Rising Water by reducing a grid puzzle to a minimax shortest-path problem. Solve it three ways — Dijkstra with max-relax, binary search plus BFS, and Kruskal-style union-find — and learn when each approach wins. A FAANG hard interview classic at Google, Amazon, and Meta.
Master longest path in a directed acyclic graph (DAG): a polynomial-time graph-DP that combines topological sort with memoised DFS. The same template solves LeetCode 329 Longest Increasing Path, course planning with prerequisites, and critical-path scheduling — a FAANG interview pattern at Google, Amazon, and Meta.
A complete walkthrough of network flow for FAANG interviews: the max-flow min-cut theorem, Ford-Fulkerson, Edmonds-Karp BFS-augmenting paths, residual graphs, and practical applications including bipartite matching and project selection. Asked at Google, Amazon, and Meta as a senior-level systems-design-meets-algorithms screen.
Eighteen advanced graph problems collapsed into one decision tree. Match the problem cue to the algorithm in seconds: MST, SCC, bridges, Floyd-Warshall, Bellman-Ford, A-star, topological sort, Eulerian paths, and max flow with complexity bounds you can quote on demand.
LeetCode 1 — Two Sum is the most-asked Amazon, Google, and Meta phone screen warmup. Single-pass hash map gives O(n) time and unlocks the complement-lookup pattern.
LeetCode 53 — find the contiguous subarray with the largest sum in O(n). Kadane is the dynamic programming gateway problem at Amazon, Google, and Meta.
LeetCode 283 — move all zeroes to the end while keeping nonzero order, in place and in O(n). The write pointer technique tested at Meta, Amazon, and Microsoft.
Find the one element that appears once while every other appears twice. The XOR bit trick delivers O(n) time and O(1) space — no extra memory, no sorting. Master the three XOR properties that make it work, then see how interviewers escalate to Single Number II and III.
LeetCode 344 is the canonical two-pointer problem — and it shows up at Meta, Microsoft, and Amazon as both a standalone question and as the foundation for palindrome checks, anagram detection, and rotate-array problems. Learn the in-place swap pattern deeply, trace through every edge case, and master the follow-ups that separate passing candidates from standout ones.
Master LeetCode 125 — Valid Palindrome with the O(1)-space two-pointer technique. Learn why every FAANG loop starts here, visualize the pointer walk on a classic example, avoid the four most common pitfalls, and unlock the palindrome follow-up chain: LC 680, LC 5, and LC 647.
LeetCode 268 hides four distinct valid solutions behind a deceptively simple problem. Learn Sort, HashSet, Gauss Formula, and XOR — understand exactly why each exists, when interviewers ask for each one, and why XOR is the most elegant answer in the room.
LeetCode 448 is the definitive interview test for index-as-a-hash-key thinking. Learn the O(n) time, O(1) space negation trick that eliminates the need for any extra data structure — and every follow-up question a FAANG interviewer will throw at you after you solve it.
Given a binary array and an integer k, find the longest run of 1s you can create by flipping at most k zeros. Master the variable sliding window pattern that solves this in O(n) time and O(1) space — and learn the follow-up questions Google and Meta actually ask after you get it right.
Learn why 3Sum is a FAANG interview staple — how sorting enables two pointers, why deduplication trips up even strong candidates, a full visual dry run, and every common bug explained with Python and JavaScript solutions.
LeetCode 11 explained from scratch: why this is a greedy problem, the formal proof that you must always move the shorter pointer, a full step-by-step dry run, common traps, and clean Python + JavaScript solutions. Master the pointer-elimination pattern that appears throughout FAANG interviews.
LeetCode 238 is one of the most frequently asked medium problems at Google and Meta. Learn why the no-division constraint is intentional, how the prefix × suffix insight unlocks the O(n) solution, and how a single running variable eliminates the extra O(n) space entirely.
Master the classic Merge Intervals problem (LeetCode 56) asked at Google, Meta, Amazon, and Microsoft. Learn why sorting by start time is the key insight, the exact overlap condition (c ≤ b), a step-by-step visual dry run, 4 common mistakes, Python and JavaScript solutions, and follow-up problems including Insert Interval, Non-overlapping Intervals, and Meeting Rooms II.
Group strings that are anagrams of each other using two canonical approaches: sorted string key O(n·k·log k) and character frequency tuple key O(n·k). Understand when the difference matters, trace through a dry run, dodge the common traps, and leave any interview with both solutions ready to go.
Master LeetCode 3 — the canonical sliding window problem. Understand the "shrink from left" insight, the critical stale-index bug with max(), and both set-based and hashmap-optimized solutions in Python and JavaScript. Includes a full step-by-step dry run and follow-up problems LC 340 and LC 159.
LeetCode 560 is one of the most-asked FAANG problems because it teaches the prefix sum + hashmap pattern — a technique that handles negative numbers, generalizes to a dozen follow-ups, and cannot be replaced by sliding window. Learn the insight, the dry run, the common mistakes, and the O(n) solution in Python and JavaScript.
LeetCode 33 is a rite of passage in FAANG interviews. Learn the one invariant that makes O(log n) possible on a rotated array, trace through a dry run, avoid the 4 most common bugs, and master the full family of follow-up problems (LC 81, LC 153, LC 154).
LeetCode 55 is a classic FAANG greedy problem that tests whether you can compress O(n²) DP thinking into a single O(n) pass. Learn the "max reachable index" insight, why greedy beats DP here, a full visual dry run, common traps, and every follow-up question interviewers ask next.
Learn how to rotate an n×n matrix 90° clockwise in-place using the elegant transpose-then-reverse trick. Understand the math behind it, see the 4-cell direct rotation alternative, dry-run through a worked example, avoid the four most common mistakes, and get clean Python + JavaScript solutions.
LeetCode 763 — asked at Amazon, Google, and Meta. Partition a string into the maximum number of pieces so each letter appears in exactly one piece. Map each character to its last occurrence, then greedily extend the current partition boundary — O(n) time, O(1) space.
LeetCode 670 — asked at Meta and Amazon. Given a non-negative integer, swap at most one pair of digits to get the maximum value. Track the last occurrence of each digit, then greedily find the leftmost position where a larger digit appears later — O(n) time, O(1) space.
LeetCode 462 — asked at Amazon, Meta, and Google. Find the minimum number of moves to equalize all array elements where each move increments or decrements one element by 1. The optimal target is the median — provable by absolute deviation minimization. O(n log n) time.
Master LeetCode 1493 with an intuition-first sliding window approach. Learn why you subtract 1 from the window size, trace through a real dry run, and ace every follow-up question an interviewer throws at you.
LeetCode 32 is one of the most deceptive Hard problems on the platform — the brute-force is obvious, but all three optimal solutions require genuinely different mental models. Master the index-sentinel stack, the DP recurrence, and the two-pass counter sweep, and you will be able to answer any follow-up a FAANG interviewer throws at you.
LeetCode 704 — the foundational FAANG binary search problem solved in O(log n) using the classic three-way exact-match template with overflow-safe midpoint.
LeetCode 278 — find the first bad version among n versions in O(log n) API calls using left-boundary binary search, the canonical FAANG predicate-search problem.
Find the k closest elements to x in a sorted array in O(log(n-k) + k) by binary searching for the optimal left boundary of the result window rather than searching for x itself.
LeetCode 4 is the most famous FAANG hard problem. Solve the median of two sorted arrays in O(log(min(m,n))) by binary searching for the correct partition position.
LeetCode 315 is a Google and Amazon classic. Count how many elements to the right are smaller than each element using merge sort with index tracking or a Fenwick Tree, both running in O(n log n).
LC 136 Single Number is the canonical XOR interview problem. Every duplicate cancels itself via a^a=0, leaving only the unique element. Master this identity and every follow-up variant before your next coding screen.
LeetCode 260 Single Number III: every element appears twice except two unique elements. Master the XOR partition trick used by FAANG interviewers to test deep bitwise reasoning.
LeetCode 338 Counting Bits: compute popcount for every integer 0..n in O(n). Master the elegant DP recurrence dp[i] = dp[i >> 1] + (i & 1) that FAANG interviewers love.
LeetCode 78 Subsets: enumerate the power set with bitmask iteration. Master the elegant 2^n bit-loop FAANG interviewers prefer over recursion for its clarity and speed.
LeetCode 698 Partition to K Equal Sum Subsets: decide if an array can be split into k equal-sum buckets. Master the bitmask DP that converts an exponential DFS into a clean O(2^n * n) solution loved by FAANG interviewers.
LeetCode 477 Total Hamming Distance: sum bit-differences across every pair in linear time. Master the per-bit contribution trick that turns O(n^2) brute force into O(n) — a FAANG favorite.
LeetCode 1879 Minimum XOR Sum of Two Arrays — pair every element of nums1 with a unique element of nums2 to minimize total XOR. Bitmask DP turns assignment into a 2^n state space. Step-by-step bit manipulation walkthrough for FAANG interviews.
LeetCode 187 Repeated DNA Sequences — find every 10-letter substring that appears twice or more. Encode each nucleotide in 2 bits, slide a 20-bit window with shift and AND. Linear-time bit manipulation interview classic.
LeetCode 1178 Number of Valid Words for Each Puzzle — count words containing the puzzle’s first letter using only puzzle letters. The 26-bit bitmask plus the (sub - 1) AND parent submask trick crushes a brute-force quadratic solution.
Strategic playbook for FAANG-specific DSA preparation. Covers Google graph and DP focus, Meta tree and string emphasis, and Amazon Leadership Principles alignment with BFS, heap and design problems.
Implement a lazy iterator over a nested integer list using a stack. Meta frequently tests this to evaluate iterator design, lazy evaluation, and stack-based tree traversal.
Encode a binary tree to a string and reconstruct it. Meta ranks this as their number-one tree interview question, testing BFS level-order traversal and string parsing under pressure.
Implement a read() function using a read4() primitive that reads exactly 4 characters at a time. Meta uses this to test buffer management, pointer arithmetic, and state machine design for file I/O.
Generate all valid combinations of n pairs of parentheses using backtracking with open and close counters. Meta asks this to test recursive thinking, pruning, and combinatorial generation under time pressure.
Count contiguous subarrays whose elements sum to k using prefix sums and a frequency hashmap. Meta asks this to test prefix sum mastery and O(N) optimization over brute-force O(N^2) solutions.
Return the rightmost visible node at each level of a binary tree using BFS level order traversal. Meta uses this to test BFS confidence, level tracking, and tree traversal variants applied to visual rendering problems.
Merge accounts that share any email address using Union-Find on email nodes. Meta uses this to test graph connectivity thinking and identity resolution — directly applicable to Facebook account deduplication systems.
Deep copy an undirected graph using DFS or BFS with a HashMap to track already-cloned nodes. Meta tests this to evaluate graph traversal, deep copy semantics, and cycle detection in recursive graph structures.
A complete cheatsheet of FAANG company-specific DSA problems, patterns, and optimal approaches. Use this as your final review before any Meta, Amazon, or Google coding interview.
The complete 1D Dynamic Programming roadmap for FAANG interviews — Fibonacci, House Robber, Kadane, Coin Change, LIS, Jump Game, Decode Ways, and Palindrome patterns with Python and JavaScript templates.
LC 70 Climbing Stairs is the canonical introduction to 1D dynamic programming. The recurrence dp[n] = dp[n-1] + dp[n-2] is pure Fibonacci, and mastering why it works — recursion to memoization to tabulation — unlocks the entire family of staircase DP problems asked at Google, Amazon, and Meta.
LC 91 Decode Ways counts the number of ways to decode a digit string as letters A-Z. The recurrence combines one-digit and two-digit transitions — a conditional Fibonacci DP. Heavily tested at Amazon, Google, and Meta because it combines string parsing, edge case handling, and DP reasoning in a single problem.
LeetCode 647 Palindromic Substrings is the canonical center-expansion problem. We derive the 2D DP recurrence, simplify it to expand-around-center for O(1) memory, and walk through a full DP table dry run with FAANG interview tips on why this beats Manacher in real interviews.
LeetCode 416 Partition Equal Subset Sum is the cleanest 0/1 knapsack disguise on the platform. We reduce it to subset-sum-equals-half, derive the boolean DP recurrence, walk through the reverse-iteration trick, and finish with a one-liner bitset version that crushes interviews.
The full 1D Dynamic Programming cheatsheet for FAANG interviews — eight pattern transitions, knapsack loop directions, LIS patience sort, and the complete problem index in one place.
The complete 2D Dynamic Programming roadmap for FAANG interviews — LCS, Edit Distance, grid path counting, interval DP, stock state machines, and 2D knapsack with Python and JavaScript templates.
LC 62 Unique Paths is the foundational 2D grid DP problem at Amazon, Google, and Meta. Learn the recurrence, space-optimize to 1D, and master the combinatorics shortcut interviewers love to ask about.
LC 1143 Longest Common Subsequence is the foundational sequence DP problem at every FAANG company. Master the 2D recurrence, space-optimize to O(n), and learn how to reconstruct the actual LCS — skills that transfer directly to Edit Distance, Shortest Common Supersequence, and Diff algorithms.
LC 72 Edit Distance (Levenshtein Distance) is the hard-level sequence DP benchmark at Google, Amazon, and Meta. Master the 3-operation recurrence, space-optimize to O(n), and understand how this algorithm powers spell-checkers, DNA alignment, and autocomplete systems.
LC 312 Burst Balloons is the classic hard-level interval DP problem asked at Google, Amazon, and Meta. The key insight is thinking in reverse — instead of choosing which balloon to burst first, choose which one to burst last in each interval. This transforms an impossible ordering problem into clean O(n^3) DP.
LC 121 Best Time to Buy and Sell Stock is the foundational stock DP problem at every FAANG company. While solvable with a one-pass greedy approach, understanding its state machine formulation (hold/not-hold states) unlocks the full stock problem series from LC 122 through LC 714.
LC 123 Best Time to Buy and Sell Stock III limits transactions to at most 2. The state machine tracks 4 explicit states — buy1, sell1, buy2, sell2 — evolving each day through clean transitions. This is the hardest single-interview stock variant and the direct precursor to the k-transactions generalization in LC 188.
LC 188 Best Time to Buy and Sell Stock IV generalizes the stock problem to at most k transactions using a 2D DP table where dp[t][i] tracks the maximum profit using t transactions through day i. This is the hardest stock variant in FAANG interviews and requires combining the k-transaction state machine with the unlimited-transaction shortcut for large k.
LC 714 Best Time to Buy and Sell Stock with Transaction Fee extends unlimited transactions by subtracting a fee on each sell. The state machine is identical to Stock II with one modification: the sell transition subtracts the fee. This is the final stock series variant and the cleanest demonstration that state machine DP is a modular framework.
LC 10 Regular Expression Matching implements "." (any char) and "*" (zero or more of preceding) using 2D DP. It is a Hard-level problem and the most complex string DP asked at Google and Meta — the star (*) handling requires 3 separate cases that trip up even experienced candidates.
LeetCode 474 Ones and Zeroes is the cleanest two-capacity 0/1 knapsack on the platform. We derive the dp[i][j] recurrence, walk a full 2D table, and ship a 1D-collapsed solution that handles the dual-resource constraint while staying interview-friendly.
The full 2D Dynamic Programming cheatsheet for FAANG interviews — seven pattern transitions, stock state machine, interval DP template, LCS reconstruction, and the complete problem index.
Solve LeetCode 200 Number of Islands with DFS flood fill in O(m*n) time. The most asked grid traversal problem at Amazon, Google, and Meta — covers DFS, BFS, and Union-Find approaches with Python and JavaScript.
Find the maximum area of any island in a binary grid using DFS that returns the size of each connected component. The canonical "DFS with return value" pattern asked at Google, Meta, and Amazon.
Capture every region of Os surrounded by Xs by inverting the problem — flood from the boundary instead of the interior. The classic boundary-DFS pattern interviewers love.
Compute the minimum minutes for rot to spread across a grid using multi-source BFS. The canonical "all sources start at the same time" pattern that solves dozens of grid-spreading problems.
For each cell, return the distance to the nearest 0. Multi-source BFS from every 0 simultaneously gives the answer in linear time — the gold-standard pattern asked at every FAANG company.
Flip at most one 0 to 1 to maximize island area. The "color the islands, then try every flip" trick avoids quadratic re-DFS — a top Google interview problem.
Find every cell from which water can flow to both oceans by reversing the flow and running DFS inward from each ocean. The reverse-flow trick that turns an O(N^4) brute force into O(N^2).
Find the shortest clear path from top-left to bottom-right in a binary grid with 8-directional movement. Pure BFS on an unweighted graph — the classic shortest-path-in-a-grid interview problem.
Find the water cell whose distance to the nearest land is maximized. Multi-source BFS from all land cells gives the answer in linear time — a top FAANG distance-spread problem.
Determine whether a word can be spelled by traversing adjacent cells without reusing any cell. The canonical DFS-with-backtracking template every grid-search interview problem builds on.
Process land additions one at a time and report the island count after each. Union-Find makes each query nearly O(1) amortized — the canonical online connectivity interview problem.
Classic graph reachability problem disguised as a puzzle. Treat each room as a node and each key as a directed edge, then run BFS or DFS from room 0 to check if every room can be visited.
An array problem masquerading as a jump puzzle. Each index is a node with two outgoing edges (i + arr[i] and i - arr[i]), and the question reduces to a textbook BFS or DFS reachability check.
A directed graph cycle-detection problem solved by Kahn topological sort (BFS) or three-color DFS. The bedrock template behind dependency resolution at Maven, npm, Bazel, Make, and every modern build system.
The natural sequel to LC 207. Instead of asking whether you can finish all courses, this problem asks for a valid course ordering. Kahn algorithm gives the answer almost for free.
A graph is a valid tree iff it is connected and has no cycles, equivalently exactly n - 1 edges and one connected component. Solve with BFS, DFS, or Union Find — Union Find is shortest.
Count connected components by Union Find (decrement count on each successful union) or by BFS / DFS (increment count for each unvisited node). Both run in near-linear time.
Find the edge that closes a cycle when added to an n-node, n-edge graph. The first edge whose two endpoints share a Union Find root is the answer — a five-line solve.
LeetCode 435 Non-Overlapping Intervals is a Meta and Amazon staple that tests interval scheduling. Sort by end time and greedily keep the earliest-ending interval to remove the minimum number in O(n log n).
LeetCode 452 Minimum Number of Arrows to Burst Balloons is a Meta and Google interval-clustering classic. Sort by end and shoot one arrow per cluster of overlapping intervals in O(n log n).
LC 739 Daily Temperatures is the most important medium-level monotonic stack problem. Unlike Next Greater Element, the stack stores indices so you can compute waiting distances. Every FAANG company uses this to gauge stack fluency.
LC 84 Largest Rectangle in Histogram is the canonical hard monotonic stack problem. The key insight — use an increasing stack and compute maximum rectangle area when a shorter bar causes a pop — unlocks both this problem and Maximal Rectangle.
LC 42 Trapping Rain Water is one of the most famous hard problems in FAANG interviews. The optimal two-pointer approach uses O(1) space. Knowing all three approaches and their trade-offs separates senior candidates from junior ones.
LC 85 Maximal Rectangle is a hard problem that reduces to running Largest Rectangle in Histogram on each row. Build cumulative height histograms row by row and apply the O(n) monotonic stack solution — the reduction is the key insight.
Reconstruct a queue from height-position pairs [h, k] where k is the count of taller or equal people in front. Sort tallest first, then insert each person at their specified position k.
Maximise score jumping through an array where each jump covers 1 to k steps. Combine DP with a monotonic deque to find the sliding window maximum of recent DP values in O(n) time.
Master the hashmap interview patterns that power 87 percent of FAANG O(1) lookup questions: complement maps, frequency counting, prefix-sum hashing, two-way bijections, and cache design across 45 LeetCode problems.
LeetCode 1 Two Sum is the most asked FAANG hashmap interview question. Master the one-pass complement HashMap that turns the brute-force O(n^2) into O(n).
LeetCode 242 Valid Anagram is a top FAANG warm-up that trains the frequency-array hashmap pattern reused in Group Anagrams, Find All Anagrams, and Minimum Window Substring.
LeetCode 383 Ransom Note is a FAANG warm-up that trains the supply-versus-demand frequency hashmap pattern reused in inventory, scheduling, and rate-limit interview questions.
LeetCode 205 Isomorphic Strings is a classic FAANG hashmap interview question that trains the bidirectional bijection check used in cipher validation, schema mapping, and Word Pattern.
LeetCode 202 Happy Number is a FAANG hashmap interview classic that trains HashSet cycle detection and the Floyd two-pointer alternative for O(1) space.
LeetCode 219 Contains Duplicate II is a FAANG hashmap interview question that trains the last-seen-index pattern and the bounded sliding-window HashSet alternative.
Group Anagrams is a medium-difficulty milestone that teaches the canonical-key grouping pattern — one of the most broadly applicable hash map techniques. Amazon, Google, and Meta use it as a filter for candidates who can design O(n k) grouping algorithms over O(n^2 k) brute-force comparisons.
Top K Frequent Elements is a classic interview problem that tests whether you know the O(n) bucket sort approach over the standard O(n log k) heap. Amazon, Google, Meta, and Microsoft all ask this problem because it reveals whether you can identify when domain constraints enable a better algorithm.
LRU Cache is one of the most important design problems in tech interviews — it combines a HashMap for O(1) lookup with a doubly linked list for O(1) eviction order. Amazon, Google, Meta, and Microsoft use it to assess system design thinking at the data structure level.
Subarray Sum Equals K is the definitive prefix-sum hash map problem. It teaches the pattern of converting a range-sum query into a complement lookup — reducing O(n^2) to O(n). Amazon, Google, and Meta ask this in nearly every data-focused interview loop.
Longest Consecutive Sequence is a deceptively hard problem that Google and Meta use to test whether candidates can achieve O(n) without sorting. The key insight — only start counting from sequence beginnings — turns an O(n^2) brute force into an O(n) HashSet solution.
Insert Delete GetRandom O(1) is a classic design interview problem that Google, Amazon, and Meta use to assess compound data structure thinking. The trick — swapping the target with the last element before deletion — enables O(1) removal from a dynamic array.
Random Pick with Weight teaches weighted random sampling — a foundational technique in machine learning, A/B testing, and traffic routing. Google and Meta use this problem to assess whether candidates understand prefix sums and binary search well enough to implement probability distributions from scratch.
Count Wonderful Substrings combines bitmask XOR with prefix parity tracking to count substrings where at most one character has an odd frequency. This advanced hashing problem teaches the bit-manipulation pattern that Google and Meta use to filter candidates for senior-level roles.
LeetCode 2364 (Medium) is a Google, Amazon, and Meta favorite. Count good pairs through a frequency map of nums[i]-i and subtract from total — a textbook complement-counting hashmap interview pattern.
LeetCode 1726 (Medium) is a Google, Amazon, and Meta hashmap interview favorite. Build a frequency map of all pair products, then apply choose-2 combinatorics and a factor of 8 to count ordered tuples.
LC 1711 Count Good Meals extends Two Sum to 22 power-of-two targets, counting pairs whose combined deliciousness is a power of 2 using a frequency map and complement lookup — tested at Amazon, Google, and Meta.
Design a simplified Twitter with follow/unfollow and a news feed that returns the 10 most recent tweets across followed users — combining hash maps, social graph storage, and k-way heap merging.
Solve LeetCode 215 Kth Largest Element using a heap (O(n log k)) or Quickselect (average O(n)). One of the most-asked Meta and Amazon interview problems.
Solve LeetCode 347 Top K Frequent Elements using a min-heap (O(n log k)) or bucket sort (O(n)). One of the most common Meta and Amazon onsite questions.
Solve LeetCode 973 K Closest Points to Origin using a max-heap (O(n log k)) or Quickselect (O(n) average). One of the most-asked Meta and Amazon problems.
Solve LeetCode 767 Reorganize String with a max-heap by always picking the two most frequent characters. A staple Amazon, Meta, and Google interview problem.
LeetCode 407 Trapping Rain Water II is a Google and Meta hard interview problem. Solve it with min-heap BFS that processes the elevation map inward from the border in O(mn log(mn)).
LeetCode 632 Smallest Range Covering Elements from K Lists is a Google and Meta hard interview problem. Solve it with a K-way merge min-heap that maintains a sliding range across K sorted lists in O(N log K).
LeetCode 355 Design Twitter is a Meta and Twitter system design interview classic. Build post, follow, unfollow, and getNewsFeed using a per-user tweet list and a K-way merge max-heap.
LeetCode 1383 Maximum Performance of a Team is a Google and Amazon hard interview classic. Use a sorted sweep over efficiency with a size-k min-heap of speeds to compute the answer in O(N log N).
LeetCode 895 Maximum Frequency Stack is an Amazon, Google, and Meta hard design interview problem. Achieve O(1) push and pop using frequency-bucket stacks — beating the naive max-heap approach.
Answer range-coverage queries offline by sorting both intervals and queries, sweeping through with a min-heap ordered by interval size — a canonical offline query pattern.
Find the kth largest level sum in a binary tree by computing all level sums with BFS and selecting the kth largest using a min-heap — a clean combination of BFS and heap selection.
Track stock prices with out-of-order timestamp updates and corrections, supporting O(log n) current, maximum, and minimum queries using a timestamp map and sorted multiset.
Find the minimum number of distinct values to remove to halve the array size by greedily eliminating the most frequent elements first — a clean greedy problem with a frequency max-heap.
A complete linked list interview playbook covering 7 core patterns (reversal, fast/slow, dummy head, merge, in-place, clone, design) with copy-paste templates and a curated index of 45 LeetCode problems mapped to every pattern.
LeetCode 206 Reverse Linked List is the foundational pointer-manipulation problem at FAANG interviews. Master the iterative three-pointer rewiring and the recursive call-stack reversal — both are used as subroutines in dozens of harder problems.
LC 1979 Find Greatest Common Divisor of Array is the entry point to GCD problems at Google and Meta. Master the Euclidean algorithm in O(log n), compute LCM without overflow, and apply extended GCD for modular inverse.
Computing C(n, r) modulo a prime appears in nearly every counting problem at Google and Meta. Master Pascal triangle for small n, precomputed factorials with modular inverse for n up to 10^6, and Lucas theorem for n up to 10^18.
Bit manipulation is the cheat code of competitive programming and tier-1 interviews. Master the XOR identities, n & (n-1) tricks, subset enumeration over a bitmask, and bitmask DP techniques that turn O(2^n) brute force into elegant constant-factor wins.
Recognising classical number sequences — Fibonacci, Catalan, triangular, Pascal-derived — is the difference between a 30-minute brute force and a 5-minute closed form. Master the recurrences, generating functions, and combinatorial interpretations every interviewer expects you to know.
Master randomized algorithms in interviews: reservoir sampling for streams, quickselect for O(n) kth element, Fisher-Yates shuffle, and Bloom filters with probability proofs.
Week 4 of the FAANG mock program runs full company-specific simulations matching the actual format, difficulty mix, and evaluation rubric of Google, Meta, and Amazon. The same problem communicated differently wins different ratings at each company.
Meta's interview format is the most speed-intensive of the major FAANG companies: 4 problems in 70 minutes across two coding rounds. This guide covers Meta's core values evaluation, the speed techniques that matter, the practice problem set with time targets, and the impact framing Meta rewards.
A practical, interview-ready guide to recursion and backtracking covering 7 core patterns, the choose-explore-unchoose template, pruning strategies, and complexity analysis. Build the mental model that unlocks subsets, permutations, combinations, partitioning, N-Queens, and Sudoku.
LeetCode 78 Subsets and 90 Subsets II are the foundation of every backtracking interview. Master the include-exclude decision tree, the duplicate-skip rule, and the bitmask alternative that interviewers use to test depth.
Master LeetCode 131 Palindrome Partitioning using backtracking with a precomputed palindrome DP table. Learn the decision tree, pruning, and FAANG interview tips.
Solve the Knight's Tour with backtracking and Warnsdorff's heuristic. Visit every square exactly once on an n by n board with O(8^(n^2)) brute force tamed by smart move ordering.
Count smaller elements to the right of every index using a Binary Indexed Tree (Fenwick Tree) with coordinate compression. The cleanest O(n log n) solution every interviewer expects.
Count pairs (i, j) with i less than j and nums[i] greater than twice nums[j]. The classic Hard problem for modified merge sort and BIT counting — the two techniques every senior interviewer expects.
Count subarray sums in [lower, upper] using merge sort or Fenwick tree on prefix sums. The flagship Hard problem connecting prefix sums, divide-and-conquer counting, and BIT range queries.
Apply many range shift operations to a string in O(n + q) using a difference array. The textbook example of when a diff array beats a segment tree, and the canonical interview signal for offline range updates.
Solve LeetCode 732 My Calendar III using a sweep-line difference array in O(n) per booking, then upgrade to a dynamic lazy segment tree with coordinate compression for O(log n) range updates and max queries.
Find the longest contiguous subarray whose sum is at most K in linear time using prefix sums plus a decreasing monotonic stack, then learn the segment tree and BIT alternatives for streaming variants.
Solve LeetCode 238 Product of Array Except Self in O(n) time and O(1) extra space using two passes of prefix and suffix products, with the segment tree and Fenwick tree extensions for the mutable variant.
The definitive guide to every stack and queue pattern asked in FAANG interviews — monotonic stack, BFS, two-stack tricks, deque, and design problems with templates and a 50-problem index.
Master the Valid Parentheses problem using a stack to match nested brackets in O(n) time. The canonical LIFO warm-up problem asked at Google, Meta, Amazon, and Microsoft — learn the hash-map trick and every edge case.
Find how many days until a warmer temperature using a monotonic decreasing stack of unresolved day indices. The canonical monotonic stack problem asked at every FAANG company — master the pattern here and unlock 20+ harder problems.
Find the next greater element for each query using a monotonic stack on nums2 and a hash map lookup in O(n+m) time. A classic application of the monotonic stack pattern combined with hash map lookups for efficient query answering.
Solve LeetCode 200 Number of Islands using BFS with a queue or DFS with a stack. The most asked grid interview question at Amazon, Google, Meta, and Microsoft, teaching connected components and flood fill.
Solve LeetCode 207 Course Schedule using Kahn algorithm BFS topological sort with a queue and indegree array. A FAANG interview classic at Amazon, Google, and Meta that tests cycle detection in a directed graph.
Solve LeetCode 210 Course Schedule II by returning an actual topological order using Kahn algorithm BFS or DFS with three colors. A FAANG interview classic at Amazon, Google, Meta, and Microsoft.
Solve LeetCode 127 Word Ladder using BFS with a queue and a wildcard pattern map for O(1) neighbor lookups. A FAANG hard at Amazon, Google, Meta, and Microsoft that tests BFS on implicit graphs.
Solve LeetCode 227 Basic Calculator II using a stack to handle operator precedence for plus, minus, multiplication, and division. A FAANG interview classic at Google, Amazon, Meta, and Uber.
Solve LeetCode 1944 Number of Visible People in a Queue in O(n) using a monotonic decreasing stack. A FAANG hard interview problem at Amazon, Google, and Meta that uses LIFO stack semantics for visibility queries.
Solve LeetCode 622 Design Circular Queue with a fixed-size array and two pointers to achieve O(1) enQueue, deQueue, Front, and Rear. A FAANG interview classic at Amazon, Google, and Meta.
Solve LeetCode 417 Pacific Atlantic Water Flow with reverse BFS from both ocean borders using a deque queue. A FAANG grid traversal classic asked at Amazon, Google, and Meta.
Solve LeetCode 1696 Jump Game VI with a monotonic deque to track the sliding window maximum of DP states in O(n). A high-signal FAANG interview problem.
Solve LeetCode 341 Flatten Nested List Iterator with a lazy stack-based approach in O(1) amortized hasNext and next. A FAANG design favorite at Google, Meta, and Amazon.
Solve LeetCode 1209 Remove All Adjacent Duplicates II in O(n) using a counter stack of (char, count) pairs. A FAANG-favorite stack twist asked at Google and Amazon.
Solve LeetCode 362 Design Hit Counter using a queue or fixed-size circular buffer for O(1) amortized hits and constant-time getHits. A FAANG system design favorite.
Solve LeetCode 84 Largest Rectangle in Histogram in O(n) using a monotonic increasing stack. The single most important monotonic stack interview problem at FAANG.
Solve LeetCode 85 Maximal Rectangle in O(m times n) by reducing each row to a histogram and applying the monotonic stack. A FAANG hard interview classic.
Solve LeetCode 224 Basic Calculator with a single-pass stack approach handling +, -, parentheses, and arbitrary whitespace in O(n). A FAANG hard parsing classic.
Solve LeetCode 295 Find Median from Data Stream with two heaps (max-heap for low half, min-heap for high half) giving O(log n) addNum and O(1) findMedian. A FAANG streaming classic.
Solve LeetCode 297 Serialize and Deserialize Binary Tree with a BFS queue producing a level-order encoding parsed in O(n). A FAANG hard tree design favorite.
Solve LeetCode 42 Trapping Rain Water in O(n) using a monotonic decreasing stack to fill water layer by layer. The signature FAANG monotonic stack hard problem.
A printable cheatsheet for the entire Stacks and Queues category — seven patterns, ready-to-paste templates, Big-O reference, and a MAANG priority order.
The Z algorithm computes Z[i] equals the length of the longest substring starting at index i that matches a prefix of the string in linear O(n) time. Cleaner than KMP for many problems and the foundation of competitive programming string toolkits.
Rabin Karp uses a polynomial rolling hash to fingerprint each window of the text and matches against the pattern hash in expected O(n + m) time. Master this and you unlock substring search, plagiarism detection, and the entire family of hash-based string problems.
Manacher finds the longest palindromic substring in O(n) by exploiting palindrome symmetry to skip redundant character comparisons. The same mirror trick that powers the Z algorithm, applied to the palindrome radius array.
Precompute polynomial prefix hashes once in O(n) and answer substring equality queries in O(1) for the lifetime of the string. The Swiss army knife behind longest duplicate substring, longest common substring binary search, and dozens of competitive programming techniques.
A suffix array sorts all suffixes of a string lexicographically. Built in O(n log n) with prefix doubling and paired with the Kasai LCP array, it answers substring search, distinct substring count, and longest repeated substring queries in optimal time.
Find the longest contiguous substring shared by two strings. The DP solution is O(n*m), binary search plus rolling hash gives O((n+m) log min(n,m)) expected, and suffix array plus LCP achieves O((n+m) log(n+m)).
The four canonical string DP problems — edit distance, longest common subsequence, interleaving strings, and regular expression matching — share a common 2D state structure. Master the family and you cover 80 percent of FAANG string DP questions.
Group anagrams, find anagram occurrences, and detect anagrams under constraints. Master the three classical encodings — sorted key, 26-bucket frequency vector, and prime-product hash — with rolling-window extensions used at Meta and Google.
Longest Palindromic Substring, Palindrome Partitioning, and Palindromic Substrings form a tight family of FAANG questions. Master expand-around-center, 2D DP, and the link to Manacher and you can adapt to any variant on the spot.
Word Search II (LC 212) is the canonical FAANG hard combining trie data structures with grid backtracking. Build a trie from the dictionary, DFS each cell, and prune aggressively to convert an exponential brute force into a fast practical algorithm.
Encode and Decode Strings (LC 271) is a deceptively simple FAANG question that mirrors how real protocols frame variable-length payloads. Master length-prefix encoding and you have the foundation for HTTP chunked transfer, Protobuf, and most binary wire formats.
Shortest Palindrome (LC 214) is a hard FAANG problem that hides a classic KMP application. Concatenate s with reversed(s) and the failure function reveals the longest palindromic prefix in linear time. Master this trick and you unlock half a dozen related KMP applications.
Counting distinct substrings of a string is the gateway problem to suffix arrays and suffix automata. Three classical solutions — n^2 hash set, suffix array plus LCP, and suffix automaton — span the full toolbox of competitive programming and FAANG hard interviews.
String Compression (LC 443) is a deceptively careful two-pointer problem with strict in-place memory requirements. Master the read-write pointer pattern and you have the blueprint for in-place array transformations across many FAANG questions.
Beyond the basic trie there is a rich landscape of advanced applications — XOR tries for maximum-XOR queries, prefix-and-suffix tries, ternary tries, compressed tries (PATRICIA), and persistent tries. Master these and you have the toolkit for half a dozen FAANG hards.
A curated and battle-tested set of the string problems that show up most often in Meta and Google onsite loops, with the canonical pattern for each. Cover this list and you cover roughly 80 percent of string-heavy FAANG screens.
LeetCode 146 LRU Cache is the most-asked design problem at FAANG. Build O(1) get and put using a doubly linked list and hashmap with full Python and JavaScript code.
LeetCode 104 — Maximum Depth of Binary Tree, asked by Amazon, Google, Meta and Apple as a phone-screen warmup. Solve it in one line of recursive DFS or with iterative BFS level counting in O(n) time.
LeetCode 226 — Invert Binary Tree, the famous Max Howell / Google whiteboard rejection question. Solve recursively in 4 lines or iteratively with BFS in O(n) time.
LeetCode 101 — Symmetric Tree, asked at Amazon, Microsoft and Bloomberg. Compare opposite subtrees with a two-pointer recursive helper to check mirror symmetry in O(n) time.
LeetCode 112 — Path Sum, asked at Amazon, Microsoft, Apple and Meta. Use DFS with a running remainder to detect any root-to-leaf path that sums to a target value in O(n) time.
LeetCode 100 — Same Tree, asked at Amazon, Meta, Google and Apple. Walk both trees simultaneously and return false on the first structural or value mismatch in O(n) time.
LeetCode 110 — Balanced Binary Tree, asked at Amazon, Meta, Google and Microsoft. Use a postorder DFS that returns -1 on imbalance to solve it in O(n) time instead of the naive O(n log n).
LeetCode 617 — Merge Two Binary Trees, asked at Amazon, Apple, Meta and Microsoft. Walk both trees in parallel, sum overlapping nodes, and reuse existing pointers in O(n) time.
LeetCode 700 — Search in a BST, asked at Amazon, Microsoft, Apple and Meta. Eliminate half the tree at each step using the BST property and finish in O(h) time, O(1) iterative space.
LeetCode 102 — Binary Tree Level Order Traversal, asked at Amazon, Meta, Google and Microsoft. The canonical BFS template that powers Right Side View, Zigzag, Largest in Each Row and 30+ other problems.
LeetCode 103 Binary Tree Zigzag Level Order Traversal — frequently asked at Amazon, Meta, Microsoft, and Bloomberg. Learn the BFS toggle pattern with deque appendleft for O(n) time.
LeetCode 199 Binary Tree Right Side View — high-frequency at Amazon, Meta, Google, and Apple. Two clean approaches: BFS taking last node per level and DFS visiting right-first.
LeetCode 113 Path Sum II — Medium tree backtracking favorite at Amazon, Meta, Microsoft. Collect every root-to-leaf path summing to target with DFS plus path append-and-pop.
LeetCode 543 Diameter of Binary Tree — top Tree DP problem at Amazon, Meta, Google, Bloomberg. Single DFS that returns height while tracking the longest path through any node.
LeetCode 98 Validate Binary Search Tree — high-frequency at Amazon, Meta, Google, Apple. Pass min and max bounds down through DFS so every node is strictly within its valid range.
LeetCode 236 Lowest Common Ancestor of a Binary Tree — Amazon, Meta, Google, Apple favorite. Single post-order DFS that returns root when either target is found, then propagates the split point upward.
LeetCode 235 Lowest Common Ancestor of a Binary Search Tree — top BST problem at Amazon, Meta, Microsoft. Iterative O(h) navigation with O(1) space using BST ordering.
Solve LeetCode 129 Sum Root to Leaf Numbers with the carry-and-accumulate DFS pattern asked at Meta, Amazon, Google, and Microsoft. Includes Python and JavaScript code, dry run, and follow-ups.
Solve LeetCode 662 Maximum Width of Binary Tree with the heap-style index trick used in Amazon, Meta, and Microsoft interviews. Includes overflow-safe BFS code in Python and JavaScript.
Solve LeetCode 1448 Count Good Nodes in Binary Tree with the DFS carry-max pattern asked at Microsoft, Meta, and Amazon. Includes Python and JavaScript code, complexity analysis, and FAANG-style follow-ups.
Solve LeetCode 652 Find Duplicate Subtrees with postorder serialization and hashing — a Google and Amazon favorite. Includes Python and JavaScript solutions with O(n^2) and O(n) approaches.
Generate all structurally unique BSTs storing values 1 to n using recursion plus memoization. LeetCode 95 is asked at Google, Amazon, and Meta to test divide-and-conquer reasoning on Catalan-number-sized search spaces.
Encode a BST compactly using preorder traversal without null markers and rebuild it with min-max bounds. LeetCode 449 is a Medium FAANG question asked at Amazon, Google, and Meta.
Solve LeetCode 2096 by finding LCA, building path strings, and replacing the start path with U moves. Asked at Amazon, Meta, and Google for FAANG-style tree pathing.
Verify a binary tree is complete with one BFS pass. Once a null child is encountered, every subsequent dequeued node must be null. LeetCode 958 is a Medium FAANG question asked at Amazon, Meta, and Microsoft.
Recover a BST where two nodes are swapped using in-order traversal to find the inversion pair. LeetCode 99 is asked at Amazon, Google, and Meta. Includes O(1) space Morris traversal solution.
LeetCode 834 Sum of Distances in Tree is a Google and Meta favorite hard problem solved in O(n) using two-pass DFS with the rerooting technique on an undirected tree.
LeetCode 429 N-ary Tree Level Order Traversal is a level-by-level BFS over a tree where each node has any number of children. Common at Amazon and Meta as a BFS warmup.
LeetCode 1161 Maximum Level Sum returns the smallest level whose node-sum is largest. Solve in O(n) with BFS level-size snapshots — a common Amazon and Meta phone-screen question.
LeetCode 2385 Amount of Time for Binary Tree to Be Infected models tree-to-graph BFS spread. Solve in O(n) by converting to an undirected graph and running BFS from the start node — common at Amazon, Google, and Meta.
LeetCode 2471 Minimum Number of Operations to Sort a Binary Tree by Level uses BFS plus minimum-swaps-to-sort-an-array. Solve in O(n log n) — a popular Google and Meta interview question.
LeetCode 173 BST Iterator implements a controlled inorder traversal with O(h) memory and amortized O(1) next. Asked at Amazon, Google, Meta, and Apple as a class-design tree question.
LeetCode 272 (Hard) frequently asked at Google and Meta. Use BST inorder traversal to get a sorted list, then a two-pointer shrink window selects the k closest values to a target in O(n) time.
Master Tries for FAANG interviews: insert, search, prefix operations, Word Search II, autocomplete, XOR binary trie for max XOR, and 5-language implementations with full problem index.
LeetCode 125 Valid Palindrome is the most common two pointer warm-up at Meta, Microsoft, and Amazon. Learn the inward-converging pointer technique that runs in O(n) time and O(1) space without building a cleaned copy of the string.
LeetCode 344 Reverse String is the simplest two pointer swap problem and a daily warm-up at Amazon, Apple, and Meta. Solve it in O(n) time and O(1) space using opposite-end pointers without allocating a new array.
LeetCode 26 Remove Duplicates from Sorted Array is the canonical fast and slow pointer deduplication problem. Microsoft, Meta, and Amazon use it to verify that candidates can compare against the previous kept element in O(n) time and O(1) space.
LeetCode 392 Is Subsequence is a Google and Amazon greedy two pointer problem. Walk both strings forward, advance the source pointer only on matches, and answer in O(m plus n) time with O(1) space.
LeetCode 1004 Max Consecutive Ones III is a Google and Amazon variable sliding window problem. Track the count of zeros inside the window and shrink from the left whenever it exceeds k to find the longest contiguous run of ones after k flips.
LeetCode 1480 Running Sum of 1D Array introduces the prefix sum technique used in dozens of FAANG range query problems. Build the running sum in O(n) time and O(1) extra space and unlock LC 303, LC 560, and LC 974.
LeetCode 3 Longest Substring Without Repeating Characters is one of the top five most asked questions at Meta and Amazon. Master the variable sliding window with a hash map to solve it in O(n) time and O(min n,m) space.
LeetCode 1423 Maximum Points You Can Obtain from Cards is asked at Google, Amazon, and Meta. Convert pick-from-ends into a fixed-size minimum-window problem in O(n).
LeetCode 930 Binary Subarrays With Sum is asked at Google, Amazon, and Meta. Count subarrays with exact sum in O(n) using atMost(goal) minus atMost(goal-1).
LeetCode 1658 Minimum Operations to Reduce X to Zero is asked at Amazon, Google, and Meta. Reframe to longest subarray summing to total minus x for an O(n) solution.
LeetCode 992 Subarrays with K Different Integers is a Google, Amazon, and Meta hard. Solve in O(n) using the atMost(K) minus atMost(K-1) decomposition.
LeetCode 487 asked at Microsoft, Meta, and Amazon. Track the last zero index instead of a counter to handle the streaming follow-up in O(n) time and O(1) space.
LeetCode 30 asked at Google, Amazon, and Meta. Run a word-aligned sliding window for each of the wlen possible offsets to find every concatenation start in O(n*wlen) time.
Complete guide to setting up and running Meta's LLaMA 3 models locally and in the cloud. Covers Hugging Face access, Ollama, quantization, chat formatting, fine-tuning with LoRA, and benchmarking for developers and ML engineers.