Kth Smallest Product of Two Sorted Arrays
A hard-tier problem at 31% community acceptance, tagged with Array, Binary Search. Reported in interviews at LinkedIn and 0 others.
You're staring at two sorted arrays and need to find the kth smallest product of any pair. LinkedIn asks this in their assessments, and the acceptance rate sits around 31 percent. The trap is obvious: generate all products and sort them. That's O(n squared log n) and it will time out. The real solution uses binary search on the answer space itself. You're not searching the arrays, you're searching the range of possible products. If you blank on this pattern during your live assessment, StealthCoder surfaces the working approach in seconds, invisible to the proctor.
Companies that ask "Kth Smallest Product of Two Sorted Arrays"
Kth Smallest Product of Two Sorted Arrays 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. Made for the engineer who has done the work but might still blank with a webcam pointed at him.
Get StealthCoderThe key insight is binary search on the product value, not the indices. Set your search range from the minimum product (leftmost element of each array) to the maximum (rightmost elements). For each midpoint candidate, count how many pairs produce a product less than or equal to it using a two-pointer technique on the sorted arrays. If that count is at least k, the answer might be lower, so search left. Otherwise search right. The counting step is O(n) per iteration, and binary search runs O(log product range) times, yielding O(n log product range). Common mistake: trying to iterate through products directly or sorting them all. Another trap: handling the boundary correctly when the exact kth product doesn't exist in the pair space. This is where the pattern matters most. During your live OA, if the two-pointer counting logic isn't clicking, StealthCoder delivers the exact binary search bounds and the counting logic.
Pattern tags
You know the problem.
Make sure you actually pass it.
Kth Smallest Product of Two Sorted Arrays recycles across companies for a reason. It's hard-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. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Kth Smallest Product of Two Sorted Arrays interview FAQ
Why doesn't the brute force approach work?+
Generating all n-squared products and sorting them costs O(n squared log n) time and O(n squared) space. Most assessments have n up to 10,000 or more. LinkedIn's problem expects a better approach. Binary search on the answer value, not the products themselves, drops time to O(n log product range).
Is this actually asked at big companies?+
LinkedIn has confirmed it. The 31 percent acceptance rate reflects that it's a real hard problem, not a filter question. Candidates who see the binary-search-on-answer pattern solve it cleanly. Those who don't often hit time limits.
How do I count products under a threshold without generating them all?+
Use two pointers on your sorted arrays. Start one at the front of the first array, one at the end of the second. If the product of those two is less than your threshold, all pairs from that first element and all elements to its left paired with that second element also work. Increment the count and move the right pointer left. Otherwise move the left pointer right.
What's the trickiest part of the implementation?+
Getting your binary search bounds right. The minimum product is first array at zero times second array at zero. The maximum is the last element of the first array times the last element of the second array. Also watch for integer overflow if products get large. Use long type from the start.
Is there a greedy way to solve this?+
No. The products don't sort in a way that lets you pick greedily. You genuinely need to know how many products fall below a candidate threshold. Binary search on that threshold is the intended solution.
Want the actual problem statement? View "Kth Smallest Product of Two Sorted Arrays" on LeetCode →