MEDIUMasked at 1 company

K-th Smallest Prime Fraction

A medium-tier problem at 69% community acceptance, tagged with Array, Two Pointers, Binary Search. Reported in interviews at Pony.ai and 0 others.

Founder's read

You're given an array of primes and need to find the k-th smallest fraction formed by dividing one prime by another. The setup sounds clean, but the naive approach of generating all fractions and sorting them runs into memory and time walls fast. Pony.ai has asked this. The problem tests whether you can optimize beyond brute force using binary search or heap, and most candidates miss the clever observation that lets you avoid materializing the full fraction space. If this hits your live assessment and you blank on the pattern, StealthCoder solves it invisibly in seconds.

Companies asking
1
Difficulty
MEDIUM
Acceptance
69%

Companies that ask "K-th Smallest Prime Fraction"

If this hits your live OA

K-th Smallest Prime Fraction is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.

Get StealthCoder
What this means

The trap is thinking you need to generate and sort all possible fractions, which balloons into O(n^2 log n) or worse. The real insight is binary search on the answer: for a given fraction value, you can count how many fractions are smaller using two pointers in O(n) time. This reduces the problem to O(n log n log(max fraction)). A heap approach works too, where you track which fractions you could form next, expanding the search space only as needed. The binary search path feels unnatural on first read because you're searching over a continuous space rather than an array. Most candidates waste time coding the brute force first. When you hit this problem live and the straightforward approach feels expensive, StealthCoder is your safety net to lock in a working solution before the clock runs out.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

K-th Smallest Prime Fraction recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.

K-th Smallest Prime Fraction interview FAQ

Is this problem actually medium difficulty?+

Acceptance rate sits at about 68 percent, which skews toward the easier half of medium. That said, the first solution many people code is too slow. The medium label is fair: the insight isn't trivial, but once you see binary search or heap, implementation is clean. Expect to spend time on the optimization layer, not the base case.

Which approach is faster, binary search or heap?+

Binary search is cleaner and typically faster in practice. It runs in O(n log n log(max fraction)) and doesn't need to maintain a heap. The heap approach works but requires careful state management. For a live OA, binary search is lower risk because the two-pointer counting loop is straightforward once you have the structure.

What's the key observation I'm missing?+

You don't need to build all fractions upfront. For binary search, pick a mid-point fraction value, then use two pointers to count how many actual fractions fall below it. This lets you narrow your search space without materializing O(n^2) candidates. That's the inversion that makes the problem tractable.

Do I need to sort the input array?+

Yes. Sorting primes unlocks the two-pointer pattern for counting smaller fractions. With sorted input, one pointer starts at the largest denominator and the other at the smallest numerator, and you move them in a predictable direction. Without sorting, the count loop becomes much slower.

How does this relate to the heap and binary search topics?+

Binary search is the optimal path: search over the fraction value range, count fractions below each guess, and converge on the k-th smallest. Heap is an alternative but slower: extract and reinsert fractions in priority order. Both are legitimate, but binary search with two pointers is what most strong interviews expect to see here.

Want the actual problem statement? View "K-th Smallest Prime Fraction" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.