Number of Beautiful Integers in the Range
A hard-tier problem at 20% community acceptance, tagged with Math, Dynamic Programming. Reported in interviews at Infosys and 0 others.
Number of Beautiful Integers in the Range is a hard DP problem that Infosys has asked. You need to count integers in a given range where the count of even digits equals the count of odd digits, and the number is divisible by k. The acceptance rate sits under 20%, which tells you the trick isn't obvious and most candidates who encounter it live blank or time out. If you hit this on your OA and the state space feels tangled, StealthCoder solves it invisibly in seconds. The real challenge is building the digit DP state correctly and avoiding off-by-one logic on the range boundaries.
Companies that ask "Number of Beautiful Integers in the Range"
Number of Beautiful Integers in the Range is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.
Get StealthCoderThe trick here is digit DP with careful state tracking. You can't just count integers naively. Instead, you build up numbers digit-by-digit, tracking: current position, whether you're still bounded by the upper limit, the balance between even and odd digits seen so far, and the remainder modulo k. The pitfall most candidates hit is forgetting to handle the lower bound properly. You need to count(upper) - count(lower - 1) to include the full range. Another trap: leading zeros. A number like '007' isn't valid, so you track whether you've placed a non-zero digit yet. Math and DP collide here. If this problem appears on your live assessment and you haven't drilled the state transitions, StealthCoder runs the solution invisible to the proctor and surfaces working code in real time.
Pattern tags
You know the problem.
Make sure you actually pass it.
Number of Beautiful Integers in the Range recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Number of Beautiful Integers in the Range interview FAQ
How hard is this problem really compared to standard digit DP?+
It's at the top tier. Standard digit DP tracks position and bounds. This adds even/odd balance and modulo state simultaneously, tripling the state space. The sub-20% acceptance rate reflects that most candidates underestimate the complexity of handling both constraints at once.
Is this still asked at top companies?+
Infosys has confirmed it. Given the low acceptance rate and the hard tag, it's not a frequent ask across most FAANG but it does appear in assessment rotations. If it lands in your OA, you're facing a sift problem designed to separate candidates.
What's the trick I'm missing when I set up the DP?+
Most candidates forget one or both of: handling leading zeros (you can't count '007' as distinct) and computing the range correctly. You must calculate count(upper) minus count(lower - 1). Skipping the minus-one step is a silent killer.
Why does the divisibility-by-k part matter?+
It forces you to track remainder state as you build the number. You can't just check divisibility at the end. You have to compute the running remainder modulo k at each step, which increases state cardinality and makes the transition logic delicate.
How do I avoid TLE on the state transitions?+
Memoization is non-negotiable. Cache by (position, is_bounded, even_count, odd_count, remainder). Without it, you'll revisit the same state thousands of times. With it, complexity is polynomial in the input size.
Want the actual problem statement? View "Number of Beautiful Integers in the Range" on LeetCode →