Meta

270 articles

dsa17 min read

Reverse String — The Two-Pointer Swap Pattern Every Interview Expects

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.

Read →
dsa13 min read

Valid Palindrome — Two Pointer Skip Non-Alphanumeric [Meta Easy]

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.

Read →
dsa15 min read

Container With Most Water — Greedy Two-Pointer Proof [Google, Amazon, Meta]

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.

Read →
dsa12 min read

Merge Intervals — The Definitive Guide (LeetCode 56) [Google, Meta, Amazon, Microsoft]

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.

Read →
dsa13 min read

Group Anagrams — Hashmap Key Design Mastery [Amazon, Google, Meta]

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.

Read →
dsa14 min read

Subarray Sum Equals K — Why Prefix Sum + HashMap Beats Everything [LC 560]

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.

Read →
dsa6 min read

Partition Labels — Greedy Last-Occurrence Interval Merging [LC 763]

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.

Read →
dsa6 min read

Maximum Swap — Greedy Last-Occurrence Digit Tracking [LC 670]

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.

Read →
dsa5 min read

Minimum Moves to Equal Array Elements II — Why the Median Wins [LC 462]

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.

Read →
dsa19 min read

Longest Valid Parentheses [Hard] — Stack, DP, and Two-Pass Counters

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.

Read →
dsa6 min read

Minimum XOR Sum of Two Arrays — Bitmask DP with XOR Pairing

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.

Read →
dsa5 min read

Meta — Subarray Sum Equals K (Prefix Sum + HashMap)

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.

Read →
dsa5 min read

Meta — Binary Tree Right Side View (BFS Level Order)

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.

Read →
dsa5 min read

Meta — Accounts Merge (Union-Find on Emails)

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.

Read →
dsa5 min read

Meta — Clone Graph (Deep Copy with DFS and HashMap)

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.

Read →
dsa10 min read

Climbing Stairs — The Gateway Problem to 1D Dynamic Programming

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.

Read →
dsa11 min read

Decode Ways — Counting Valid Decodings with Conditional Fibonacci DP

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.

Read →
dsa6 min read

Palindromic Substrings — Expand Around Center vs 2D DP

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.

Read →
dsa7 min read

Partition Equal Subset Sum — 0/1 Knapsack on a Boolean Array

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.

Read →
dsa9 min read

Longest Common Subsequence — The Essential Sequence DP Problem for FAANG

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.

Read →
dsa10 min read

Burst Balloons — Interval DP with Reverse Thinking (The Hardest Grid DP Pattern)

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.

Read →
dsa8 min read

Best Time to Buy and Sell Stock — Single Transaction State Machine 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.

Read →
dsa9 min read

Best Time to Buy and Sell Stock III — At Most 2 Transactions State Machine

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.

Read →
dsa9 min read

Best Time to Buy and Sell Stock IV — At Most k Transactions 2D DP

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.

Read →
dsa10 min read

Best Time to Buy and Sell Stock with Transaction Fee — State Machine DP with Cost

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.

Read →
dsa7 min read

Ones and Zeroes — 2D 0/1 Knapsack with Two Capacities

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.

Read →
dsa7 min read

Course Schedule — Cycle Detection via Topological Sort

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.

Read →
dsa7 min read

Graph Valid Tree — Cycle and Connectivity Check

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.

Read →
dsa6 min read

Daily Temperatures — Monotonic Stack With Index Distances

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.

Read →
dsa6 min read

Maximal Rectangle — Applying Histogram Analysis Row by Row

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.

Read →
dsa8 min read

Group Anagrams — Canonical Keys and the Group-By Pattern

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.

Read →
dsa9 min read

Top K Frequent Elements — Bucket Sort Beats the Heap

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.

Read →
dsa9 min read

Subarray Sum Equals K — Prefix Sums and the Complement Map

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.

Read →
dsa9 min read

Longest Consecutive Sequence — HashSet and the Smart Sequence Start

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.

Read →
dsa9 min read

Insert Delete GetRandom O(1) — The Array+HashMap Design Trick

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.

Read →
dsa9 min read

Random Pick with Weight — Prefix Sums and Probabilistic Sampling

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.

Read →
dsa10 min read

Count Wonderful Substrings — Bitmask XOR and Prefix Parity Maps

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.

Read →
dsa6 min read

Count Good Meals — Power-of-Two Complement Counting

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.

Read →
dsa6 min read

Design Twitter — K-Way Merge News Feed Interview

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.

Read →
dsa7 min read

Daily Temperatures — Monotonic Decreasing Stack Explained

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.

Read →
dsa7 min read

Next Greater Element I — Monotonic Stack with HashMap

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.

Read →
dsa8 min read

Word Search II — Trie + DFS Backtracking on a Grid

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.

Read →
dsa8 min read

Shortest Palindrome — KMP Failure Function on a Concatenated String

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.

Read →