7
var findKthNumber = function (m, n, k) {8
// lo always points to a value which is9
// not going to be our answer13
// the loop stops when lo and hi point to two adjascent numbers14
// because lo is always incorrect, hi will contain our final answer16
// As a general practice don't do a (lo + hi) / 2 because that17
// might cause integer overflow18
const mid = lo + Math.floor((hi - lo) / 2);19
const count = countLessThanEqual(mid, m, n);21
// Find the minimum mid, such that count >= k31
function countLessThanEqual(target, rows, cols) {33
// we move row by row in the multiplication table34
// Each row contains at max (target / rowIndex) elements less than35
// or equal to target. The number of cols would limit it though.36
for (let i = 1; i <= rows; i++) {37
count += Math.min(Math.floor(target / i), cols);