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 →
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 →
56Maximal Square: the 2D dynamic programming pattern on a grid.▼mediumGoogleMetaAmazon1 replies◆ premiumThe textbook grid DP where each cell depends on three neighbors at once. What interviewers want is the min-of-three recurrence, plus the reason it has to be min. The answer follows.Open full answer →