Count how many ways a digit string can be decoded into letters using the mapping 1->A, 2->B, ..., 26->Z.
You are given a string of digits. Each non-empty segment of 1 or 2 digits can represent a letter if it maps to a value from 1 to 26, where 1 corresponds to A and 26 corresponds to Z.
Return the number of different ways to decode the entire string into letters.
A decode is valid only if every chosen segment is within the range 1 to 26 and segments do not start with 0.
s consisting only of digits.s represents the encoded message.s.1 <= s.lengths contains only characters '0'-'9'0.1 to 26 are allowed.Example 1
Input
s = "12"
Output
2
Explanation
The string can be decoded as "AB" (1, 2) or "L" (12).
Example 2
Input
s = "226"
Output
3
Explanation
Valid decodings are "BBF" (2,2,6), "BZ" (2,26), and "VF" (22,6).
Example 3
Input
s = "06"
Output
0
Explanation
No valid decoding starts with 0.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.