Hard · Backtracking

Decode Numbers

Given a string of digits, return every way to decode it into lowercase letters with the keys "1"→a through "26"→z (each key is one or two digits and none starts with 0), in any order — an empty list when no decoding exists.

Examples

Example 1

{
  "digits": "12"
}

Output: 2 decodings

Example 2

{
  "digits": "226"
}

Output: 3 decodings

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 Backtracking problems