Binary Search | Commented
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\n\nclass Solution:\n    def kthSmallestProduct(self, nums1: List[int], nums2: List[int], k: int) -> int:\n        # Naive - O(N^2 * logN)\n        # BS over answer - O(log2(10 ^ 10) * n * log2(n))\n        nums1.sort()\n        nums2.sort()\n        \n        def findRank(product: int) -> int:\n            ans = 0\n            \n            for num1 in nums1:\n                if num1 == 0:\n                    if product >= 0: ans += len(nums2)\n                    continue\n                # simple maths\n                # n1 * n2 <= prod\n                # if n1 > 0, n2 <= prod / n1\n                # else, n2 >= prod / n1\n                if num1 < 0:\n                    # greater than or equal to\n                    ans += len(nums2) - bisect_left(nums2, ceil(product / num1))\n                else:\n                    # everything less than or equal to \n                    ans += bisect_right(nums2, product // num1)\n            return ans\n\n        l, r = -int(1e10), int(1e10)\n        while l < r:\n            mid = l + (r - l) // 2\n            if findRank(mid) >= k:\n                r = mid\n            else:\n                l = mid + 1\n        return r\n```
['Python3']