FastPrepDecode Ways
Problems/Decode Ways

Decode Ways

JP Morgan Chase logoJP Morgan Chase● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a JP Morgan Chase intern online assessment. Both reports name Decode Ways, and one links the standard exercise. This version keeps the linked mapping, the zero rules, the limit of 100 characters and the guarantee that the answer fits in 32 bits. We wrote the other tests. Our version is about 95% the same as the reported tasks.

Map the numbers 1 through 26 to the letters A through Z. Return how many ways the entire string digits can be split into valid one-digit or two-digit numbers under this mapping.

A piece cannot begin with zero. For example, 10 and 20 are valid pieces, but 0, 06, and 30 are not.

Function

numDecodings(digits: String) → int

Examples

Example 1

digits = "12"return = 2

The valid partitions are 1|2 and 12, corresponding to AB and L.

Example 2

digits = "226"return = 3

The valid partitions are 2|2|6, 22|6, and 2|26, corresponding to BBF, VF, and BZ.

Example 3

digits = "06"return = 0

The leading zero cannot form a valid piece. In particular, 06 is not the same code as 6.

Constraints

  • 1 <= digits.length <= 100
  • digits contains only ASCII decimal digits 0 through 9.
  • The number of valid decodings is at most 2^31 - 1.

More JP Morgan Chase Online Assessment questions

  • Find Total CostOA · Seen Oct 2026
  • Minimum Meeting RoomsOA · Seen Oct 2026
  • Count Dropped RequestsOA · Seen Oct 2026
  • Maximize Minimum Deployment DifficultyOA · Seen Oct 2026
  • Task SchedulingOA · Seen Oct 2026
  • Substring RemovalOA · Seen Oct 2026
  • Maximum Game Board ScoreOA · Seen Sep 2026
  • Minimum Digit Changes Between String HalvesOA · Seen Sep 2026
  • Same Substring Within BudgetOA · Seen Sep 2026
  • Invert Ad Visibility BitsOA · Seen Aug 2026

Similar questions at other companies

  • Maximum Equal-Bit Pairs in a SubsequenceAmazon · OA
  • Longest Subsequence That Is a SubstringBooking.com · OA
  • Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OAMicrosoft interview questions
  • Palindrome CounterGoldman Sachs · OAGoldman Sachs interview questions
  • Longest String ChainVisa · OAVisa interview questions
  • Minimum-Cost Digit String DecodingSquadStack.ai · OA
  • Maximum Redundancy After One Segment FlipBloomberg LP · OABloomberg LP interview questions
  • Substrings Without a Target SubsequencePhonePe · OAPhonePe interview questions
  • Minimum Edit-Distance String for Each QueryTarget · OA
  • Longest Subsequence That Is a SubstringWells Fargo · OAWells Fargo interview questions

Interview reports that mention this question

  • JP Morgan Chase Data and AI Intern Superday: 11 Experiences
  • JPMorgan Tech Intern HackerRank OA: 11 Experiences (Part 3 of 5)

JP Morgan Chase interview experiences

  • JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)
  • JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
  • JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
  • JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)
All JP Morgan Chase interview questionsSee JP Morgan Chase hiring insights
Saved
class Solution {
    public int numDecodings(String digits) {
        // Write your code here.
    }
}
Checking account…