CoursesDynamic Programming

Sequence & String DP

Lessons
9
Exercises
56
Minutes
61
  1. 1

    Two Strings, One Table

    Two-sequence DP compares PREFIXES: dp[i][j] answers the question for the first i chars of s and the first j of t — match takes the diagonal + 1, mismatch combines the neighbors.

    Multiple choice
    6 exercises
    5 min
  2. 2

    Is Subsequence

    One greedy walk over t decides it: always advance the t pointer, advance the s pointer only on a match — then reframe the same question as a prefix table to bridge into LCS.

    DebugMultiple choiceTrace
    6 exercises
    6 min
  3. 3

    Longest Common Subsequence

    THE prefix table: dp[i][j] = LCS of the first i chars of a and first j of b — match takes the diagonal + 1, mismatch takes the better neighbor, and dp row i pairs with a.charAt(i-1), not a.charAt(i).

    Complete codeDebugMultiple choiceTrace
    6 exercises
    7 min
  4. 4

    Longest Palindromic Subsequence

    A palindrome reads the same in both directions, so it survives in reverse(s) too — LPS(s) collapses to LCS(s, reverse(s)), the table you already know.

    Complete codeMultiple choiceTrace
    6 exercises
    7 min
  5. 5

    Word Break

    dp[i] = can the first i characters be segmented — true when SOME split point j has dp[j] true and s[j..i) in the dictionary. Every split point stays in play; greedy longest-match does not.

    Complete codeMultiple choiceTrace
    6 exercises
    7 min
  6. 6

    Delete Operation for Two Strings

    Both strings can only shrink, so what survives is a common subsequence — keep the longest one and delete everything else: steps = m + n - 2·LCS.

    Complete codeMultiple choiceTrace
    6 exercises
    6 min
  7. 7

    Sequence DP CheckpointCheckpoint

    No new concepts — carry the prefix table to unseen ground: the shortest string that contains two others, crossing-free lines between arrays, deletions that charge by ASCII weight, and counting the ways a pattern hides inside a string.

    Complete codeMultiple choiceTrace
    6 exercises
    7 min
  8. 8

    Sequence DP ReviewReview

    Mixed recap of the island: what a prefix-table cell actually says, match-diagonal versus mismatch-neighbors, the reductions catalog, where the answer lives for ending-style versus prefix-style states, the segmentation loop, and rolling a table down to two rows.

    Complete codeCode orderMultiple choice
    6 exercises
    6 min
  9. 9

    Boss: Longest Increasing SubsequenceBoss

    The island's final test: the longest strictly increasing subsequence. One ending-style recurrence prices every chain at once — and the boss's traps are reading the last cell as the answer, settling for contiguous runs, and letting equal elements pretend to climb.

    Complete codeDebugCode orderMultiple choiceTrace
    8 exercises
    10 min
AlgoFox Pro

Dynamic Programming is part of AlgoFox Pro

You can read the whole course outline here. The exercises are in the app, along with your streak, your mistake review, and the progress that carries across your devices.

Pro starts with a 3 day free trial. The app store decides who is eligible for an introductory offer, and a lapsed subscription does not get another one.

Download AlgoFox on the App StoreGet AlgoFox on Google Play

Already subscribed in the app? Sign in with the same account and Pro works here too. Quick Play and Battle are free on the web, and so is the first course in every subject.