[Java] Binary Search
~~~java\n\nclass Solution {\n    public long kthSmallestProduct(int[] nums1, int[] nums2, long k) {\n        if (nums1 == null || nums2 == null) {\n            
~~~java\n\nclass Solution {\n    public long kthSmallestProduct(int[] nums1, int[] nums2, long k) {\n        if (nums1 == null || nums2 == null) {\n            return -1;\n        }\n        \n        long left = (long) -1e10;\n        long right = (long) 1e10;\n        while (left + 1 < right) {\n            long mid = left + (right - left) / 2;\n            long count = countSmallerOrEqual(nums1, nums2, mid);\n            if (count < k) {\n                left = mid + 1;\n            } else {\n                right = mid;\n            }\n        }\n\n        return countSmallerOrEqual(nums1, nums2, left) >= k ? left : right;\n    }\n    \n    private long countSmallerOrEqual(int[] nums1, int[] nums2, long target) {\n        long count = 0;\n        \n        for (int n1 : nums1) {\n            int left = 0, right = nums2.length - 1;\n            \n            while (left + 1 < right) {\n                int mid = left + (right - left) / 2;\n                long prod = (long)n1 * nums2[mid];\n                \n                if (n1 >= 0) {\n                    if (prod <= target) {\n                        left = mid;\n                    } else {\n                        right = mid - 1;\n                    }\n                } else {\n                    if (prod <= target) {\n                        right = mid;\n                    } else {\n                        left = mid + 1;\n                    }\n                }\n            } \n            \n            long currCount = 0;\n            if (n1 >= 0) {\n                if ((long) n1 * nums2[right] <= target) {\n                    currCount = right + 1;\n                } else if ((long) n1 * nums2[left] <= target) {\n                    currCount = left + 1;\n                } else {\n                    currCount = 0;\n                }\n            } else {\n                if ((long) n1 * nums2[left] <= target) {\n                    currCount = nums2.length - left;\n                } else if ((long) n1 * nums2[right] <= target) {\n                    currCount = nums2.length - right;\n                } else {\n                    currCount = 0;\n                }\n            }\n            count += currCount;\n        }\n        \n        return count;\n    }\n}\n\n~~~
[]