← All questions
MediumCoding

Ugly Number III

Asked atMedia.net
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Binary search the candidate value x.
  2. 02Count numbers up to x divisible by a, b, or c.
  3. 03Use inclusion-exclusion with gcd-based LCMs.
  4. 04Find the first x whose count reaches n.

Reference answer

Then expect these follow-ups

  • Why is the count predicate monotone?

    Tests: binary search proof

  • How do you cap an overflowing LCM?

    Tests: integer safety

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question