Nth Video ID Built Only From Prime Factors 2, 3 and 5
Last updated: November 29, 2026
Quick Overview
A legacy ID scheme only issues positive integers whose prime factors are all in {2, 3, 5}, with 1 counted first. Return the nth such ID.
0
0
0 solved
A legacy ID scheme only issues positive integers whose prime factors are all in {2, 3, 5}, with 1 counted first. Return the nth such ID.
A Google phone-screen classic in a playful ID-generation frame. Candidates usually start with a min-heap plus a seen set, and strong candidates then show the three-pointer DP that avoids the log factor.
What the Interviewer Expects
- Generates numbers in order instead of testing each integer
- Uses a min-heap with deduplication
- Or uses three pointers into the generated list
- Explains why duplicates arise (6 = 2*3 = 3*2)
- States O(n log n) or O(n)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Generalize to an arbitrary list of primes
- What is the growth rate of the nth value?
- Can you find the count of such numbers up to N quickly?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: n >= 1.
- Output: the nth smallest positive integer whose only prime factors are 2, 3 and 5 (1 is the first)....
High-Level Design
Every valid number after 1 is 2, 3 or 5 times a smaller valid number. So generate them in order: start a min-heap with 1. Pop the smallest, and push it times 2, 3 and 5. The nth pop is the answer. Dup...