#786

K-th Smallest Prime Fraction

pupil · 575 · lc medium +29 · verified · 69% accepted · 2,134 likes · top 76%

Description

You are given a sorted array arr of unique integers that includes 1 and only prime numbers. Consider all fractions arr[i] / arr[j] where 0 <= i < j < arr.length. Return the kth smallest such fraction as a two-element array [arr[i], arr[j]].

Example 1:

Input: arr = [1,2,3,5], k = 3
Output: [2,5]
Explanation: The fractions to be considered in sorted order are:
1/5, 1/3, 2/5, 1/2, 3/5, and 2/3.
The third fraction is 2/5.

Example 2:

Input: arr = [1,7], k = 1
Output: [1,7]

Code

1
2
3