Count Four-Digit Codes with Sum S

Problem Overview

  • Count how many 4-digit codes (digits 0–9, leading zeros allowed) have a digit sum equal to S.
  • Input: integer S in [0..36]; Output: the number of valid codes.
  • Context: relevant to PIN/security code distributions and checksum-style constraints.
  • Source: a Google interviews coding interview question; classic combinatorics problem.
  • Ideal for practicing reasoning on an interview question with precise constraints.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: