PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Morgan Stanley

Count decodings of a digit string

Last updated: Mar 29, 2026

Quick Overview

This question evaluates algorithmic problem-solving focused on dynamic programming, string processing, and correct handling of invalid prefixes and zeros in combinatorial decodings, categorized under Coding & Algorithms.

  • Medium
  • Morgan Stanley
  • Coding & Algorithms
  • Software Engineer

Count decodings of a digit string

Company: Morgan Stanley

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Take-home Project

You are given a non-empty digit string s consisting of characters '0'–'9' and a mapping where 1->'a', 2->'b', ..., 26->'z'. Return the number of valid ways to decode s. Note that '0' cannot be decoded alone and is only valid as part of '10' or '20'. Provide an O(n) time solution, explain how to handle zeros and invalid prefixes, analyze time and space complexity, and implement in C++. Optionally include a space-optimized variant.

Quick Answer: This question evaluates algorithmic problem-solving focused on dynamic programming, string processing, and correct handling of invalid prefixes and zeros in combinatorial decodings, categorized under Coding & Algorithms.

Related Interview Questions

  • Implement Factorial and Squares - Morgan Stanley (medium)
  • Compute maximum non-overlapping meetings - Morgan Stanley (medium)
  • How do you escape the circle? - Morgan Stanley (medium)
  • Compute win probability in coin-toss game - Morgan Stanley (easy)
  • Compute minimal cost to merge numbers - Morgan Stanley (Medium)
Morgan Stanley logo
Morgan Stanley
Jul 16, 2025, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
2
0

You are given a non-empty digit string s consisting of characters '0'–'9' and a mapping where 1->'a', 2->'b', ..., 26->'z'. Return the number of valid ways to decode s. Note that '0' cannot be decoded alone and is only valid as part of '10' or '20'. Provide an O(n) time solution, explain how to handle zeros and invalid prefixes, analyze time and space complexity, and implement in C++. Optionally include a space-optimized variant.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Morgan Stanley•More Software Engineer•Morgan Stanley Software Engineer•Morgan Stanley Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,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.