Kth Smallest Number in Multiplication Table LeetCode solution in C++
1class Solution {2public:3int findKthNumber(int m, int n, int k) {4int high = m * n, low = 1;56int mid = 0, ans = 1e9;7while (low <= high) {8mid = low + (high - low) / 2;9int temp = 0;1011// for each i find the max value ,less than or equal to n , such that12// i*j<=mid13// add j to answer14for (int i = 1; i <= m; i++) temp += min(mid / i, n);1516if (temp >= k) {17ans = min(ans, mid);18high = mid - 1;19} else20low = mid + 1;21}22return ans;23}24};