PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Snapchat

Count ways to decode digit string

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's skill in dynamic programming and combinatorial reasoning about string partitioning, testing competency in counting valid decodings under constraint handling and edge-case analysis.

  • hard
  • Snapchat
  • Coding & Algorithms
  • Software Engineer

Count ways to decode digit string

Company: Snapchat

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

You are given a string `s` consisting of digits `'0'` to `'9'`. The string encodes a message using the following mapping: - `'1'` → `A`, `'2'` → `B`, ..., `'26'` → `Z`. A **decoding** is a way to partition `s` into one or more contiguous substrings, where each substring represents a valid number between `1` and `26` (inclusive), and then map each number to its corresponding letter. Examples of valid decodings: - `"12"` can be decoded as `"AB"` (`1 2`) or `"L"` (`12`), so there are 2 ways. - `"226"` can be decoded as `"BZ"` (`2 26`), `"VF"` (`22 6`), or `"BBF"` (`2 2 6`), so there are 3 ways. Rules: - A single `'0'` is **not** a valid code. - Any two-digit number must be between `10` and `26` inclusive. - Encodings like `"06"` or `"30"` are invalid because `0` cannot start a number, and `30` is not between 10 and 26. **Task** Given `s`, return the total number of different valid decodings. **Constraints** - `1 <= len(s) <= 100` - `s` consists only of characters `'0'`–`'9'`. You may assume the result fits in a 32-bit signed integer.

Quick Answer: This question evaluates a candidate's skill in dynamic programming and combinatorial reasoning about string partitioning, testing competency in counting valid decodings under constraint handling and edge-case analysis.

Related Interview Questions

  • Determine Whether Courses Can Be Completed - Snapchat (medium)
  • Solve Decimal Coin Change - Snapchat (medium)
  • Find Maximum Island Perimeter - Snapchat (medium)
  • Solve Three Algorithmic Tasks - Snapchat (hard)
  • Implement a Timestamped Counter - Snapchat (medium)
Snapchat logo
Snapchat
Dec 8, 2025, 7:38 PM
Software Engineer
Onsite
Coding & Algorithms
8
0

You are given a string s consisting of digits '0' to '9'. The string encodes a message using the following mapping:

  • '1' → A , '2' → B , ..., '26' → Z .

A decoding is a way to partition s into one or more contiguous substrings, where each substring represents a valid number between 1 and 26 (inclusive), and then map each number to its corresponding letter.

Examples of valid decodings:

  • "12" can be decoded as "AB" ( 1 2 ) or "L" ( 12 ), so there are 2 ways.
  • "226" can be decoded as "BZ" ( 2 26 ), "VF" ( 22 6 ), or "BBF" ( 2 2 6 ), so there are 3 ways.

Rules:

  • A single '0' is not a valid code.
  • Any two-digit number must be between 10 and 26 inclusive.
  • Encodings like "06" or "30" are invalid because 0 cannot start a number, and 30 is not between 10 and 26.

Task

Given s, return the total number of different valid decodings.

Constraints

  • 1 <= len(s) <= 100
  • s consists only of characters '0' – '9' .

You may assume the result fits in a 32-bit signed integer.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Snapchat•More Software Engineer•Snapchat Software Engineer•Snapchat Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.