You are given two integers m and n representing the dimensions of a multiplication table, and an integer k. The multiplication table is formed such that the value at position (i, j) is equal to i × j. Your task is to return the kth smallest number in this multiplication table.
Example 1
Input: m = 3, n = 3, k = 5
Output: 3
Explanation: The multiplication table is: 1 2 3 2 4 6 3 6 9 All elements in sorted order are [1,2,2,3,3,4,6,6,9]. The 5th smallest number is 3.
Example 2
Input: m = 2, n = 3, k = 6
Output: 6
Explanation: The multiplication table is: 1 2 3 2 4 6 All elements in sorted order are [1,2,2,3,4,6]. The 6th smallest number is 6.
Example 3
Input: m = 4, n = 5, k = 8
Output: 4
Explanation: The multiplication table is: 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 All elements in sorted order are [1,2,2,3,3,4,4,4,5,6,6,8,8,9,10,12,12,15,16,20]. The 8th smallest number is 4.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
3 3 5
3
2 3 6
6
3 5 7
4