K-th Smallest Prime Fraction
Given a strictly increasing array arr consisting of 1 and distinct prime numbers, consider every fraction arr[i]/arr[j] with i < j. Return the kth smallest such fraction as a two-element array [arr[i], arr[j]].
Open official problem prompt ↗Find the kth smallest value among all arr[i]/arr[j] fractions without materializing and sorting the O(n^2) list of them.
Merging many already-sorted playlists into one ordered stream: peek the current front song of each playlist, always take the globally earliest, and pull the next song from whichever playlist you just drew from.
- Input
- arr = [1, 2, 3, 5], k = 3
- Output
- [2, 5]
- Why
- Sorted fractions are 1/5, 1/3, 2/5, 1/2, 3/5, 2/3; the 3rd smallest is 2/5, returned as [2, 5].
2 <= arr.length <= 10001 <= arr[i] <= 3 * 10^4arr[0] == 1arr[i] for i > 0 is a prime numberAll numbers in arr are unique and sorted in strictly increasing order1 <= k <= arr.length * (arr.length - 1) / 2