Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Kth Smallest In Multiplication Table

Medium Acceptance 75.00% Points 30.00

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.

Examples
Example 1

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

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

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.

Hints
Hint 1
N/A
Constraints
  • 1 = m, n = 3 × 104
  • 1 = k = m × n
Companies
Amazon
Topics
Binary Search
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions