Count Four-Digit Codes with Sum S

Problem Overview

  • Compute how many four-digit codes (0000–9999) have digits summing to S.
  • Input: integer S; Output: count of such codes.
  • Constraints: S ∈ [0..36]; leading zeros are allowed.
  • Real-world context: counting valid PIN combinations under a digit-sum rule.
  • From Google interviews; a classic coding interview problem and interview question.

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: