Approach: Binary Search on the Answer ValueYou can’t jump straight to the k-th smallest value, but given a candidate“x”, you can count in O(m) how many entries in the table are ≤ x:Row“i” contains“i, 2i, 3i, …, n·i”, so the entries ≤ x in that row number“min(n, x // i)”. Sum over all rows.“count(x)” is monotonically non-decreasing, so binary search for the smallest x with count(x) ≥ k — that x is exactly the k-th smallest number.class Solution:def findKthNumber(self, m: int, n: int, k: int) - int:if m n: # make m the smaller dimensionm, n n, mdef count_le(x: int) - int: Number of entries in the multiplication table that are x. cnt 0 for i in range(1, m 1): cnt min(n, x // i) if cnt k: # early exit: we only care whether cnt k break return cnt lo, hi 1, m * n # answer always lies in [1, m*n] while lo hi: # standard lower_bound template mid (lo hi) // 2 if count_le(mid) k: hi mid else: lo mid 1 return lo # lo hi k-th smallestKey detailsSwap when“m n” so the inner loop runs only“min(m, n)” times.Breaking early once“cnt k” avoids pointless iterations on large inputs.The“while lo hi” “hi mid” pattern is a lower-bound search: on exit“lo” is the answer directly, no extra return logic needed.ComplexityTime: O(m · log(m·n)) with m min(m, n)Space: O(1)Verification: cross-checked against brute force for all“m, n ≤ 12” and every valid“k” — zero mismatches. Also matches the official cases:“findKthNumber(3,3,5) 3”,“findKthNumber(2,3,6) 6”,“findKthNumber(42,34,401) 126”.