Kth Smallest Number in Multiplication Table
Problem Description
Given three integers m, n, and k, return the k-th smallest element in the m x n multiplication table.
The multiplication table is an m x n grid where entry (i, j) = i * j (1-indexed).
Pattern: Binary search on the answer. For a candidate x, count how many entries in the table are ≤ x: for each row i, there are min(floor(x/i), n) entries ≤ x. Find smallest x where count ≥ k.
Example 1:
Input: m = 3, n = 3, k = 5
Output: 3
Explanation: Table = [[1,2,3],[2,4,6],[3,6,9]], sorted = [1,2,2,3,3,4,6,6,9], 5th = 3.
Example 2:
Input: m = 2, n = 3, k = 6
Output: 6
Example Test Cases
Example 1
Input: [3,3,5]
Expected: 3
Example 2
Input: [2,3,6]
Expected: 6
Example 3
Input: [3,3,1]
Expected: 1
Run your code to see the results