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

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Dynamic Programming problems