1124. Decode Ways — Count Decodings

EasyDynamic Programming1D DPString DP

A message of digits is encoded where 'A'->1, ..., 'Z'->26. Given a digit string s, return the number of ways to decode it. A leading zero or an invalid pairing yields zero ways. The input is JSON {s}.

Input: JSON {s}.

Output: Integer — the number of decodings.

Examples

Example 1
Input: {"s":"12"}
Output: 2
Explanation: 'AB' or 'L'.
Example 2
Input: {"s":"226"}
Output: 3
Explanation: 'BZ', 'VF', or 'BBF'.
Example 3
Input: {"s":"06"}
Output: 0
Explanation: Leading zero is invalid.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →