FastPrepAlphanumeric Combinations
Problems/Alphanumeric Combinations

Alphanumeric Combinations

Goldman Sachs logoGoldman Sachs● MediumOA

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Special thanks: Full Stack Dev shared this problem.

John is teaching his son Rob English alphabet and number counting. He reperesents 'a' as the 1st character, 'b' as the 2nd character up to 'z' as the 26th character. John says 'kite' can be representd as '119205'. The 11th character is 'k', 9th character is 'i', 20th character is 't' and 5th character is 'e'.

Rob being smarter than him, says '119205' can also mean 'aaite' (1)(1)(9)(20)(5), 'aste'(1)(19)(20)(5), etc. Now being enthusiastic about it, John wants to know given a string os length n containing digits from 0 to 9, how many such words are possible.

Input Format

You are given a string S containing characters from 0-9. You have to find how many such words are possible for that given number sequence,

Output Format

A single integer returning the number of words. If there are no possible combinations output will be 0.

Function

alphanumericCombinations(S: String) → int

Examples

Example 1

S = "2112"return = 5

2112 can be represented as: (2)(1)(1)(2) is represented as baab (2)(1)(12) is represented as bal (2)(11)(2) is represented as bkb (21)(1)(2) is represented as uab (21)(12) is represented as ul Therefore, the answer in this case is 5 :)

Example 2

S = "2101"return = 1

(2)(10)(1) is the only solution. Heads up 🙌 Do not consider (01) to be 'a' as this can be chained to (001), (0001).

Constraints

  • 💃💃

More Goldman Sachs interview questions

  • Best Average Student ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Hash MapOA · PHONE SCREEN · Seen Nov 2026
  • House Robber IIIPHONE SCREEN · Seen Nov 2026
  • Knight Probability in ChessboardONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · Seen Nov 2026
  • Maximum Ones After K OperationsOA · Seen Nov 2026
  • Palindrome CounterOA · Seen Oct 2026
  • Longest Palindromic SubsequenceOA · Seen Oct 2026
  • Check a Complete Binary TreePHONE SCREEN · Seen Oct 2026
  • Meeting RoomsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Longest Palindromic SubsequenceAXQ Capital · OA
  • 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
  • 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
All Goldman Sachs interview questionsSee Goldman Sachs hiring insights
Saved
class Solution {
    public int alphanumericCombinations(String s) {
      // write your code here
    }

}
Checking account…