Problem · Math

Count Digit Holes

Learn this problem
EasyIBM logoIBMFULLTIMEOA
See IBM hiring insights

Problem statement

Certain decimal digits contain closed loops, or holes, when written:

  • Digits 0, 4, 6, and 9 each contain one hole.
  • Digit 8 contains two holes.
  • Digits 1, 2, 3, 5, and 7 contain no holes.

Given an integer number, return the total number of holes across all of its digits.

Function

countDigitHoles(number: int) → int

Examples

Example 1

number = 649578return = 5

Digits 6, 4, and 9 contribute one hole each, while digit 8 contributes two. The total is 5.

Example 2

number = 123return = 0

None of the digits 1, 2, or 3 contains a hole.

Example 3

number = 1000000000return = 9

The leading 1 contributes no holes, and each of the nine zeroes contributes one.

Constraints

  • 1 <= number <= 10^9.

More IBM problems

drafts saved locally
public int countDigitHoles(int number) {
  // Write your code here.
}
number649578
expected5
checking account