12Solve 'longest substring without repeating characters' and explain the sliding-window / two-pointer pattern.▼medium★ EssentialMetaAmazonGoogle1 replies○ sign inSliding window is one of the highest-yield coding patterns, and this is its canonical problem. The real signal is spotting when a window collapses an O(n squared) scan into one linear pass, and holding the invariant cleanly.Open full answer →
25Validate balanced parentheses/brackets, and explain the stack pattern.▼easy★ EssentialGoogleMetaAmazon2 replies◆ premiumA warm-up that tests for the stack instinct. Interviewers look for recognizing that last-opened-first-closed maps onto a stack, plus handling the edge cases (leftover opens, early close). The pattern follows.Open full answer →
33Edit distance (Levenshtein): the 2D dynamic programming pattern.▼hardGoogleMetaAmazon1 replies◆ premiumEdit distance is the archetypal 2D string DP, powering spell-check, diff, and fuzzy matching. What interviewers watch for: naming the subproblem and the insert/delete/replace recurrence. Here is the answer.Open full answer →
39Word Break: can a string be segmented into dictionary words?▼mediumGoogleMetaAmazon1 replies◆ premiumWord Break is the classic 1D string DP that snags people who reach for greedy or naive recursion. What interviewers watch for: the dp[i] = 'is the prefix of length i segmentable' recurrence, plus why a locally valid split can doom the rest. Here is the answer.Open full answer →
45Longest Common Subsequence (LCS) and the 2D DP family.▼mediumGoogleMetaAmazon1 replies◆ premiumLCS is the template 2D-sequence DP behind diff tools and bioinformatics. Interviewers look for rebuilding the match/mismatch recurrence from memory and not mixing up subsequence (gaps allowed) with substring (contiguous). The answer follows.Open full answer →
49Minimum Window Substring: the variable-size sliding window.▼hardGoogleMetaAmazon1 replies◆ premiumMinimum Window Substring is the hard sliding-window problem that probes expand-and-contract with a character-count map. Interviewers look for the grow-to-valid then shrink-to-minimal pattern, verified in O(1) per step.Open full answer →
51Group Anagrams: the canonical-key hash-map pattern.▼mediumGoogleMetaAmazon2 replies◆ premiumGroup Anagrams probes the 'compute a canonical key and bucket by it' pattern. Interviewers look for choosing a key that anagrams share without comparing every pair. The answer follows.Open full answer →
58Decode Ways: count the decodings of a digit string (1D DP).▼mediumGoogleMetaAmazon1 replies◆ premiumDecode Ways is a 1D DP whose difficulty sits entirely in the edge cases: zeros and the valid 1-26 range. Interviewers look for the take-one-digit-or-two recurrence plus disciplined validity checks. The answer follows.Open full answer →
59Longest Palindromic Substring (expand around center).▼mediumGoogleMetaAmazon2 replies◆ premiumThis classic has a tidy O(n^2) expand-around-center solution that outdoes the naive O(n^3). Interviewers look for expanding from every center and handling odd and even lengths separately. The answer follows.Open full answer →
90Generate all valid combinations of n pairs of parentheses.▼mediumGoogleMetaAmazon1 replies◆ premiumGenerating then filtering costs O(2^(2n)) and wastes effort. Backtracking with two counters builds only valid strings by applying the balance rule at every step. Here is the template and why the pruning conditions are exactly right.Open full answer →
94Implement a basic calculator that evaluates a string with +, -, *, /, and parentheses.▼hardGoogleMetaAmazon2 replies◆ premiumWorking out arithmetic with precedence and nested parentheses is a parsing task, and a single stack manages both neatly. The traps are operator precedence, multi-digit numbers, and the sign of truncated division. Here is a one-pass solution.Open full answer →