Medium · Dynamic Programming

Decode Ways

Given a string s of digits, return the number of ways to split it into codes 1–26 and read each code as a letter (1 → A through 26 → Z); a code never starts with 0, so '06' is invalid, and the answer is 0 when s cannot be decoded.

Examples

Example 1

s = "226"

Output: 3 ways

Example 2

s = "12"

Output: 2 ways

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Dynamic Programming problems