Problem Β· Dynamic Programming

Count Four-Digit Codes with Sum S

Learn this problem
● EasyGoogle logoGoogleINTERNNEW GRADOA
See Google hiring insights

Problem statement

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.

πŸ“’πŸ“’ Many many thanks to Rachel and Aura Man!! πŸ§‘πŸ’œπŸ’›πŸ’šπŸ©΅πŸ’–

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 problems

drafts saved locally
public int googleCountCodeWithSum(int S) {
  // write your code here
}
S35
expected4
checking account