FastPrepCount Four-Digit Codes with Sum S
Problems/Count Four-Digit Codes with Sum S

Count Four-Digit Codes with Sum S

Google logoGoogle● EasyINTERNNEW GRADOA

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Special thanks: Rachel and Aura Man helped with this problem.

Consider all codes made of four digits (0-9). How many of them have a sum of digits equal to S? For example, for S = 4, there are 35 such codes in total. Some of them are 0022, 1003, 1111, 2020, 4000.

that, given an integer S, returns the number of four-digit codes whose sum of digits is equal to S.

Assume that:

  • S is an integer within the range [0..36].

In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.

Function

googleCountCodeWithSum(S: int) → int

Examples

Example 1

S = 35return = 4

The possible codes for S = 35 are: 9998, 9989, 9899, 8999. Therefore, the function should return 4.

Example 2

S = 4return = 35

🍊🍊

Example 3

S = 2return = 10

🍊

Constraints

  • S is an integer within the range [0..36].

More Google interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Minimum Operations to Make a SubsequenceOA · Seen Nov 2026
  • Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Enough Muffins for the LineSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
  • Count Routes Through Four Shop TypesOpenAI · OAOpenAI interview questions
  • Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OAMicrosoft interview questions
  • Count Combinations Using Weights One Through KConfluent · OAConfluent interview questions
  • Pressure-Isolation Shutdown OrderIntuit · OAIntuit interview questions
  • Stable Workload Redistribution TreesTower Research Capital · OA
  • Count Bounded Share TransactionsOptiver · OAOptiver interview questions
  • Count Valid A-B-C Sequences Under a Modulo-Four RuleInfosys · OAInfosys interview questions
  • Count Strictly Increasing Subsequences of Length 3IBM · OAIBM interview questions

Interview reports that mention this question

  • Google OA: What It Tests (2026)
  • Google New Grad OA, Tokens and Digit Codes: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int googleCountCodeWithSum(int S) {
      // write your code here
    }

}
Checking account…