Isomorphic Strings:Map Both Directions, Not One
s maps onto t when each letter has one partner and that partner has only s. A single HashMap hides collisions the other way; two maps (or two last-seen indexes) catch them.
Read More21 questions
s maps onto t when each letter has one partner and that partner has only s. A single HashMap hides collisions the other way; two maps (or two last-seen indexes) catch them.
Read MoreThe shared prefix of a list of strings is the first column that disagrees. Pairwise shrinks waste work; one vertical scan stops at the first mismatch.
Read MoreThe longest palindrome you can build from letter counts is every even pair plus at most one odd center. This is not the longest palindromic substring of the original string.
Read MoreA Roman string is a left-to-right sum unless a smaller numeral sits before a larger one. Nested replace of IV/IX pairs works; one peek at the next value is enough.
Read MoreTwo strings are anagrams when their letter frequencies match. Sorting both is honest and slower; one count array (or a map) answers in linear time.
Read MoreA phrase is a palindrome after you ignore punctuation and case. Building a cleaned copy works; two pointers from the ends answer without the extra string.
Read MoreA digit string decodes as letters 1–26. Recursing on every split is exponential; a linear pass counts ways to land on i from a legal one-digit or two-digit tail.
Read MoreTurning word1 into word2 is the cheapest insert, delete, or substitute at each prefix pair. Recursing on three ops explodes; a DP grid fills each cell from three neighbors.
Read MoreEvery anagram of p inside s is a window of the same length whose counts match. Rechecking each slice is quadratic; one sliding frequency pass returns every start index.
Read MoreAnagrams share a letter signature. Pairwise checks are honest and quadratic; one map from sorted letters (or a count key) to a list groups them in a pass.
Read MoreEach digit opens a keypad bucket. Nested loops freeze the length; backtracking walks the digits, appends one letter, and undoes so the next choice sees a clean path.
Read MoreThe longest shared subsequence of two strings is a DP grid: match both letters or skip one. Enumerating subsequences is exponential; the grid answers in O(mn) without requiring a contiguous slice.
Read MoreThe longest palindrome sitting inside the string is found by expanding around 2n−1 centers. Checking every i..j is honest and cubic; a DP table matches the O(n²) bound with extra space you do not need.
Read MoreThe longest same-letter stretch after at most k replacements is a window whose length minus the majority count stays ≤ k. Nested slices are honest; one grow/shrink pass is enough.
Read MoreThe longest unique-character stretch is a window that grows on the right and jumps the left past a repeat. Nested uniqueness checks are honest and quadratic.
Read MoreEvery partition of s into palindromic slices is a cut that is legal only if the prefix is already a palindrome. Nested splits explode; backtracking tries each end, undoes, and continues.
Read MoreEvery palindromic window counts, including single letters. Nested i..j checks are honest; expanding around 2n−1 centers is the same walk as longest palindromic substring, with a counter instead of a best slice.
Read Mores2 contains a permutation of s1 when some window of length s1 matches its letter counts. Sorting every slice is honest; one sliding count answers in linear time.
Read MoreWord order reverses after you drop extra spaces. split and reverse a list is honest; reversing the whole buffer then each word does the same job without a token array.
Read Mores segments if some dictionary words cover it end to end. Recursing on every prefix is exponential; a boolean array records which indexes a word can land on, and a set answers membership.
Read More