Java | Binary Search | Beats 100% Solutions
Code\njava []\nclass Solution {\n    public long kthSmallestProduct(int[] nums1, int[] nums2, long k) {\n        int segregated1[][] = segregate(nums1);\n      
# Code\n```java []\nclass Solution {\n    public long kthSmallestProduct(int[] nums1, int[] nums2, long k) {\n        int segregated1[][] = segregate(nums1);\n        int neg1[] = segregated1[0];\n        int pos1[] = segregated1[1];\n        int segregated2[][] = segregate(nums2);\n        int neg2[] = segregated2[0];\n        int pos2[] = segregated2[1];\n        \n        long negProd = (long) neg1.length * pos2.length + (long) pos1.length * neg2.length;\n\n        int arr1[], arr2[], arr3[], arr4[];\n        if(k <= negProd) {\n            reverse(pos1);\n            reverse(pos2);\n            arr1 = neg1;\n            arr2 = pos2;\n            arr3 = neg2;\n            arr4 = pos1;\n        } else {\n            k -= negProd;\n            reverse(neg1);\n            reverse(neg2);\n            inverse(neg1);\n            inverse(neg2);\n            arr1 = neg1;\n            arr2 = neg2;\n            arr3 = pos1;\n            arr4 = pos2;\n        }\n        long start = (long) -1e10, end = (long) 1e10;\n        while(start <= end) {\n            long mid = start + (end - start) / 2;\n            long count = countSmallerEqual(arr1, arr2, mid) + countSmallerEqual(arr3, arr4, mid);\n            if(count < k) {\n                start = mid + 1;\n            } else {\n                end = mid - 1;\n            }\n        }\n        return start;\n    }\n\n    private long countSmallerEqual(int A[], int B[], long num) {\n        int i = 0, j = B.length - 1;\n        long count = 0;\n        while(i < A.length && j >= 0) {\n            if(num < (long) A[i] * B[j]) {\n                j--;\n            } else {\n                count += j + 1;\n                i++;\n            }\n        }\n        return count;\n    }\n\n    private void inverse(int nums[]) {\n        for(int i = 0; i < nums.length; i++) {\n            nums[i] = -nums[i];\n        }\n    }\n\n    private void reverse(int nums[]) {\n        int i = 0, j = nums.length - 1;\n        while(i < j) {\n            int temp = nums[i];\n            nums[i] = nums[j];\n            nums[j] = temp;\n            i++;\n            j--;\n        }\n    }\n\n    private int[][] segregate(int nums[]) {\n        ArrayList<Integer> negatives = new ArrayList<>(); \n        ArrayList<Integer> positives = new ArrayList<>(); \n        for(int i = 0; i < nums.length; i++) {\n            if(nums[i] < 0) {\n                negatives.add(nums[i]);\n            } else {\n                positives.add(nums[i]);\n            }\n        }\n        int[] negativeArray = negatives.stream().mapToInt(i -> i).toArray();\n        int[] positiveArray = positives.stream().mapToInt(i -> i).toArray();\n        return new int[][]{negativeArray, positiveArray};\n    }\n}\n```
['Java']