Class Solution
-
- All Implemented Interfaces:
public final class Solution
786 - K-th Smallest Prime Fraction\.
Medium
You are given a sorted integer array
arr
containing1
and prime numbers, where all the integers ofarr
are unique. You are also given an integerk
.For every
i
andj
where0 <= i < j < arr.length
, we consider the fractionarr[i] / arr[j]
.Return the <code>k<sup>th</sup></code> smallest fraction considered. Return your answer as an array of integers of size
2
, whereanswer[0] == arr[i]
andanswer[1] == 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
Constraints:
2 <= arr.length <= 1000
<code>1 <= arri<= 3 * 10<sup>4</sup></code>
arr[0] == 1
arr[i]
is a prime number fori > 0
.All the numbers of
arr
are unique and sorted in strictly increasing order.1 <= k <= arr.length * (arr.length - 1) / 2
Follow up: Can you solve the problem with better than <code>O(n<sup>2</sup>)</code> complexity?
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
Modifier and Type Method Description final IntArray
kthSmallestPrimeFraction(IntArray arr, Integer k)
-
-
Method Detail
-
kthSmallestPrimeFraction
final IntArray kthSmallestPrimeFraction(IntArray arr, Integer k)
-
-
-
-