FastPrepCount Decodings of a Digit String
Problems/Count Decodings of a Digit String

Count Decodings of a Digit String

Bank of America logoBank of America● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported by a Bank of America candidate as one of two coding tasks in a timed test with recorded answers, the first round of the process. The report only links to the task: count the ways a string of digits can be decoded when 1 to 26 stand for A to Z.

The report gives no examples, limits or rule for very large counts. Here, the string has up to 10,000 digits and may contain zeros, and the count is returned modulo 10^9 + 7.

Our version is about 85% the same as the reported question.

A message of capital letters was encoded by replacing each letter with its position in the alphabet: A becomes 1, B becomes 2, and so on up to Z, which becomes 26. The numbers were then written one after another with no separators.

Given the digit string digits, return the number of ways to split it into pieces so that every piece is a number from 1 to 26 written without a leading zero. Each such split decodes to one message. If no split works, return 0.

The count can be very large, so return it modulo 10^9 + 7.

Function

countDecodings(digits: String) → int

Examples

Example 1

digits = "2611"return = 4

The splits are 2 6 1 1 (BFAA), 26 1 1 (ZAA), 2 6 11 (BFK) and 26 11 (ZK). The middle 6 and 1 cannot form one piece, because 61 is larger than 26.

Example 2

digits = "1020"return = 1

A 0 cannot be a piece on its own, so each 0 must join the digit before it. The only split is 10 20, which decodes to JT.

Example 3

digits = "804"return = 0

The 0 cannot stand alone, and joined to the 8 it makes 80, which is larger than 26. No split works, so the answer is 0.

Constraints

  • 1 <= digits.length <= 10^4
  • digits consists only of the characters 0 to 9.

More Bank of America Online Assessment questions

  • Return Exact Cash Register ChangeOA · Seen Aug 2026
  • Sum Skipping Multiples of 7OA · Seen Nov 2025
  • Wildcard Substring MatchOA · Seen Nov 2025
  • Maximum String BeautyOA · Seen Sep 2024
  • Merge Point of Two Linked ListsOA · Seen Oct 2023
  • Remove Duplicates from a ListOA · Seen Oct 2023
  • Pairs with Target Sum in a Sorted ArrayOA · Seen Oct 2023
  • Count Level-Order Traversals of a TreeOA · Seen Sep 2023
  • Count Set BitsOA · Seen Sep 2023
  • Count Pairs with Sum KOA · Seen Jun 2023

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

Bank of America interview experiences

  • Bank of America interviews · December 2025
  • Bank of America OA · December 2025
  • Bank of America interviews · September 2026
  • Bank of America OA · September 2026
All Bank of America interview questionsSee Bank of America hiring insights
Saved
class Solution {
    public int countDecodings(String digits) {
        // write your code here
    }
}
Checking account…