FunctionRacerProblemsRace

Distinct Codes of a Length

HardDynamic programmingPython, JavaScript, TypeScript, Java, C++

Cross out any letters of text you like and read the remaining letters in order. Return how many different strings of exactly size letters you can get this way, modulo 1,000,000,007.

A string that can be read in several ways counts once. size = 0 gives 1 (the empty string), and a size larger than len(text) gives 0.

Example 1

text "abab"
size 2
returns 4

The strings are aa, ab, ba and bb. ab can be picked in three ways but counts once.

Example 2

text "aabb"
size 2
returns 3

Only aa, ab and bb: no b comes before an a.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Dynamic programming problems