Problem · Math
Count Digit Holes
Learn this problemProblem statement
Certain decimal digits contain closed loops, or holes, when written:
- Digits
0,4,6, and9each contain one hole. - Digit
8contains two holes. - Digits
1,2,3,5, and7contain no holes.
Given an integer number, return the total number of holes across all of its digits.
Function
countDigitHoles(number: int) → intExamples
Example 1
number = 649578return = 5Digits 6, 4, and 9 contribute one hole each, while digit 8 contributes two. The total is 5.
Example 2
number = 123return = 0None of the digits 1, 2, or 3 contains a hole.
Example 3
number = 1000000000return = 9The leading 1 contributes no holes, and each of the nine zeroes contributes one.
Constraints
1 <= number <= 10^9.