2040. Kth Smallest Product of Two Sorted Arrays
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python3 []
from bisect import bisect_left, bisect_right
from math import ceil

class Solution:
    def kthSmallestProduct(self, nums1, nums2, k):
        def valid_pairs(x):
            count = 0
            for num in nums1:
                if num > 0:
                    count += bisect_right(nums2, x // num)
                elif num < 0:
                    count += len(nums2) - bisect_left(nums2, ceil(x / num))
                elif num == 0 and x >= 0:
                    count += len(nums2)
            return count

        low, high = -10**10 - 1, 10**10 + 1

        while low + 1 < high:
            mid = (low + high) // 2
            if valid_pairs(mid) >= k:
                high = mid
            else:
                low = mid

        return low + 1

```
['Python3']