Unique Digits in Range
Reported by candidates from Agoda's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Agoda's May OA included a digits-focused range problem where most candidates blank on the optimization. You're given a range and need to count or identify numbers with unique digits only. The naive loop-through-every-number approach works small ranges but tanks on 1 to 1,000,000. StealthCoder will give you the digit-DP or math shortcut in real time if you freeze, but the pattern is recognizable once you see it: you're counting valid numbers, not iterating them.
Pattern and pitfall
This is a digit dynamic programming or counting problem disguised as range math. The trick is computing how many numbers in range [a, b] have all unique digits. Build a count function for [0, n], then answer is count(b) - count(a - 1). DP state tracks position in the number, which digits you've used (bitmask), whether you're still bounded by n, and whether you've started placing non-zero digits. The pitfall: forgetting to handle leading zeros as 'not yet started.' StealthCoder catches the DP transitions instantly, so you can code faster under pressure and avoid the off-by-one on digit transitions.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Unique Digits in Range 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. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as count numbers with unique digits. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Agoda's OA.
Agoda reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Unique Digits in Range FAQ
Do I really need digit DP for this?+
Yes, on large ranges. Brute force fails at n > 100,000. Digit DP is O(10 * 10! * 2 * position) for the count function, much faster. Small ranges might pass naive loops, but Agoda tests scale.
What's the bitmask for?+
Track which digits 0-9 you've already used in the current number. A number is valid if no digit repeats, so your bitmask must never have two bits set for the same digit. XOR and popcount help here.
Why do I need 'started' flag in DP state?+
Leading zeros don't count as digits used. The number 00123 is really 123. Without a started flag, you'd mark 0 as used too early and reject valid numbers.
How do I test this fast without running the full range?+
Hardcode small ranges like [1, 100] or [10, 99] by hand. Verify 9 single-digit numbers pass, 81 two-digit numbers pass (10-98 except repeats). Spot-check your DP on these.
Is this still the Agoda OA pattern or have they moved on?+
Digit DP and range counting stay in top-tier OAs because they filter hard. Agoda was asking this in May 2025. Expect it or a graph variant.