Count Digit Holes
Reported by candidates from IBM's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The classic trap in this IBM OA question, reported in August 2026, is the zero. Count Digit Holes looks like a ten-line warmup, and it is. But a sloppy digit loop can quietly drop the zeros, and Example 3 (1000000000 returns 9) exists to catch exactly that. The pattern is math: peel off digits, map each one to its hole count, sum. You've seen this shape before. If your brain freezes mid-assessment, StealthCoder sits invisibly on your screen as a safety net and hands you the solution in real time.
The problem
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 = 649578 return = 5 Digits 6, 4, and 9 contribute one hole each, while digit 8 contributes two. The total is 5. Example 2 number = 123 return = 0 None of the digits 1, 2, or 3 contains a hole. Example 3 number = 1000000000 return = 9 The leading 1 contributes no holes, and each of the nine zeroes contributes one. Constraints 1 <= number <= 10^9.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is a lookup table: 0, 4, 6, 9 are worth 1, 8 is worth 2, everything else is 0. Then extract digits with number % 10 and number // 10 until the number hits zero, adding as you go. The pitfall is the loop condition and the zero digit. Since the constraint says number >= 1, a while number > 0 loop is safe, and interior zeros still get processed because you're checking the digit, not the remaining value. People who special-case zero or only count 4, 6, 8, 9 get Example 3 wrong. Converting to a string and iterating characters works just as well and sidesteps the arithmetic. Max input is 10^9, so ten digits at most. Complexity is trivial either way. If you blank on the mapping during the live OA, StealthCoder can surface the clean version in seconds.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Count Digit Holes cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass IBM's OA.
IBM reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count Digit Holes FAQ
How hard is Count Digit Holes really?+
Easy. It's a digit-sum problem with a custom weight table. The only way to miss is forgetting that 0 has a hole or that 8 has two. If you can write a loop with modulo 10, you can finish this in a few minutes.
What's the trick to this IBM question?+
Build a map: 0, 4, 6, 9 give 1, and 8 gives 2. Then walk the digits and sum. The trick is just not forgetting zero, since Example 3 with nine trailing zeros is the case that punishes a naive mapping.
Should I use string conversion or modulo arithmetic?+
Either passes. Converting to a string and looping over characters is shorter and harder to get wrong. Modulo and integer division avoids the conversion and is just as fast at 10^9. Pick whichever you can write without thinking.
What edge cases should I test?+
Test 1000000000, which should return 9, since it checks interior zeros. Test 123 for a zero result. Test a single digit like 8 for two holes. The minimum input is 1, so you don't need to handle 0 as the whole number.
How do I prepare for this in 48 hours?+
Don't over-prep this one. Write the digit-extraction loop once from memory and run the three examples. Then spend your time on harder patterns like arrays, hash tables, and two pointers, since a warmup like this is rarely the whole assessment.