The Kth Smallest Number in Multiplication Table interview question asks you to find the smallest integer in an table where table[i][j] = i * j. The values in the table are between and . Because the table can be , you cannot build or sort it.
Companies like Google and Uber ask this to test your ability to perform Binary Search on the answer space. It tests whether you can use a mathematical shortcut to count how many numbers are less than in a multiplication table in time. It evaluation your Binary Search interview pattern proficiency.
This follows the Binary Search on Value pattern.
min(X / i, n).sum(min(X / i, n)) for all from 1 to .count(X) >= k.. Table:
1 2 3
2 4 6
3 6 9
Sorted: 1, 2, 2, 3, 3, 4, 6, 6, 9. is 3.
mid = 4.count(X) >= k logic.Binary Search on the answer is the secret to almost all "Kth something in a virtual matrix" problems. Whenever you can't build the dataset, check if you can easily "count elements less than ."
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Nth Magical Number | Hard | Solve | |
| Smallest Good Base | Hard | Solve | |
| Preimage Size of Factorial Zeroes Function | Hard | Solve | |
| Nth Digit | Medium | Solve | |
| Reach a Number | Medium | Solve |