Java Solution | Binary Search
So we want to find out k-th smallest product from the two sorted arrays. Let\'s first find out the range of our answer. So the minimum value it can go is if we 
So we want to find out k-th smallest product from the two sorted arrays. Let\'s first find out the range of our answer. So the minimum value it can go is if we have elements -10^5 in both the arrays so the minimum value is -10^10 and similarly for maximum value it is 10^10. Now we can do a binary search in our range and for every current product we can check whether we have atleast k products that are less than current product. If we do have atleast k products that are less than current product then we move our window left, otherwise to the right.\n\nOk so now we know what we have to do, lets now see how would we do what we wanna do?\n\nSo we iterate over nums1 and count the number of products that are less than current product.\nHere three cases arise:\n1. currentElement = 0: 0 * any number in nums2 will be 0. So if current product>=0 then we know that the whole array(nums2) would be included in our count.\n2. currentElement>0: then we find maximum index in nums2 such that currentElement * nums2[maxIndex] is less than equal to current product. Then we can add maxIndex+1 elements into our count as they are less that equal to current product.\n3. currentElement<0: then we do exact reverse of what we did in the previous case. We find minimum element that satisfies currentElement * nums2[minIndex]<= current product.\n\nCode :\n```\nclass Solution {\n    public long kthSmallestProduct(int[] nums1, int[] nums2, long k) {\n        long l = (long)-1e11;\n        long r = (long)1e11;\n        long res = 0;\n        while ( l<=r ) {\n            long mid = (l+r)/2;\n            // checking whether we have k at least k elements whose product is less than the current product\n            // if yes then we know we have to move left\n            if ( check(mid, nums1, nums2, k) ) {\n                r = mid - 1;\n                res = mid;\n            } else {\n                l = mid + 1;\n            }\n        }\n        return res;\n    }\n    public boolean check ( long mid, int[] nums1, int[] nums2, long k ) {\n        long cnt = 0;\n        for ( int i=0; i<nums1.length; i++ ) {\n            long val = (long) nums1[i];\n            // if current element is 0 and we out current product is >= 0 then we can add the whole second array because 0*anything will be 0\n            if ( val==0 && mid>=0 ) {\n                cnt += nums2.length;\n            } else if ( val<0 ) {\n                // If we encounter negative value we find the minimum index in the second array such that this element * minIndexElement <= current product\n                cnt += findMinIndex(val, mid, nums2);\n            } else if ( val>0 ) {\n                // if we encounter positive element we find max index in the second array such that this element * maxIndexElement <= current product\n                cnt += findMaxIndex(val, mid, nums2);\n            }\n        }\n        // if we have atleast k elements whose product is less than current product\n        return cnt>=k;\n    }\n    public long findMaxIndex( long val, long mid, int[] nums2 ) {\n        int l = 0;\n        int r = nums2.length - 1;\n        // when no element in second array when multiplied by the current element of the first array yields result less that current product we will return res+1 hence -1 + 1 hence 0 coz there are no elements which when multiplied by current element of the first array yield result less than current product.\n        long res = -1;\n        while ( l<=r ) {\n            int m = (l+r)/2;\n            if ( val*nums2[m]<=mid ) {\n                // if our current product is >= val*current element then we move the window to right side in order to find max index with which when multiplied the element of the first array is still less than current product.\n                res = (long)m;\n                l = m + 1; \n            } else {\n                r = m - 1;\n            }\n        }\n        // so we have found res+1 elements who satisfy our condition. +1 coz res would give index\n        return res+1;\n    }\n    public long findMinIndex( long val, long mid, int[] nums2 ) {\n        int l = 0;\n        int r = nums2.length - 1;\n        // when all elements of second array multiplied by current element of first array yield result > current product then we return 0 coz there are no elements which would yield us result.\n        long res = r + 1;\n        while ( l<=r ) {\n            int m = (l+r)/2;\n            if ( val*nums2[m]<=mid ) {\n                r = m - 1;\n                res = (long)m;\n            } else {\n                l = m + 1;\n            }\n        }\n        return nums2.length - res;\n    }\n}\n```
['Binary Tree', 'Java']