LeetCode 115 Distinct Subsequences - Problem Statement

The problem

Count the number of distinct subsequences of s that equal t.

A subsequence keeps characters in order but can skip elements.

With s = "rabbbit", t = "rabbit":

  • You can form "rabbit" by choosing different 'b's from "rabbbit".
  • Pick b at index 2: ra[b]bbit → rabbit.
  • Pick b at index 3: rab[b]bit → rabbit.
  • Pick b at index 4: rabb[b]it → rabbit.
  • 33 distinct ways.

With s = "babgbag", t = "bag":

  • Multiple ways to pick 'b', 'a', 'g' from s.
  • 55 distinct subsequences.

Constraints: 11 \le s.length, t.length 1000\le 1000.