Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Decode Ways

Medium

Topics
StringDynamic Programming

A message of digits is encoded to letters using the mapping 'A' -> 1, ..., 'Z' -> 26. Given a digit string s, return the number of ways to decode it. The answer fits in a 32-bit integer.

Example 1

Input:  s = "12"
Output: 2
Explanation: "AB" (1 2) or "L" (12).

Example 2

Input:  s = "226"
Output: 3

Example 3

Input:  s = "06"
Output: 0

Constraints

  • 1 <= s.length <= 100
  • s contains only digits and may contain leading zeros.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access