Trains the technique from
LeetCode 2040Kth Smallest Product of Two Sorted ArraysThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Two lists of readings are given as nums1 and nums2, each already in non-decreasing order. Either may hold negative readings.
Take every product of one reading from the first list with one from the second, keeping every combination of positions even when the products repeat. Return the k-th smallest of those products, counting from one.
Example 1
The twelve products in order run -24, -12, -10, -6, -5, -2, 0, 0, 0, 3, 18 and 20, so the seventh is nothing.
Example 2
The only product is a negative reading times a positive one.
Example 3
The four products are 6, 8, 15 and 20, so the second is 8.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def kth_smallest_product(nums1: list[int], nums2: list[int], k: int) -> int:public long kthSmallestProduct(int[] nums1, int[] nums2, long k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.