[C++] || Code for Beginners || Binary Search || Reference for future me :)
Binary search for the Kth value, in the isPossible function check how hany products can be formed from nums1, nums2 whose product is less than your assumed valu
Binary search for the Kth value, in the isPossible function check how hany products can be formed from nums1, nums2 whose product is less than your assumed value. It should be greater than k, otherwise its quite obvious you would not get kth value if your number of elements are less than K\n\nTo find the products from both array, loop on array1 and binary search on array2 to find the count of products which can be less than your guessed value.\n\nIf your element in array1 is positive, obviously, you need to multiply it with smallest negatives to minimise the product and hopefully make it smaller than your guessed value\nand\nIf your element in array1 is negative, you need to multiply it with all the largest positives in array2 such that the product becomes less than guessed value\n\n```\nclass Solution {\npublic:\n     int maximiseSmall(vector<int> &nums2 ,long long val ,long long midval){\n        int l=0;\n        int r=nums2.size()-1;\n        int res= -1;\n        while(l<=r){\n            long long mid=(l+r)/2;\n            if(val*nums2[mid]<=midval){  /* maximise the left side of nums2 as val is positive\n\t\t\t\t\t\t\t\t\t\t\tand hence we need to have as many negative/small\n\t\t\t\t\t\t\t\t\t\t\tnumbers which are mostly found on left side */\n                res=mid;\n                l=mid+1;\n            }\n            else{\n                r=mid-1;\n            }\n        }\n        return res+1;\n    }\n    \n    int maximiseLarge(vector<int> &nums2 ,long long val ,long long midval){\n        int l=0;\n        int r=nums2.size()-1;\n        int res=nums.size()+1;\n        while(l<=r){\n            long long mid=(l+r)/2;\n            if(val*nums2[mid]<=midval){  /* maximise the right side of nums2 as val is negative\n\t\t\t\t\t\t\t\t\t\t    and hence we need to have as many positive/large\n\t\t\t\t\t\t\t\t\t\t\tnumbers which are mostly found on right side,\n\t\t\t\t\t\t\t\t\t\t\tas negative*positive=negative. So finally we subtract\n\t\t\t\t\t\t\t\t\t\t\tres from nums2.size() to get how many numbers were on \n\t\t\t\t\t\t\t\t\t\t\tthe right side */\n                res=mid;\n                r=mid-1;\n            }\n            else{\n                l=mid+1;\n            }\n        }\n        return nums2.size()-res;\n    }\n    \n    bool isPossible(vector<int> &nums1, vector<int> nums2, long long midval, long long k){\n        long long cnt=0;\n        for(int i=0;i<nums1.size();i++){\n            long long val=nums1[i];                        \n\t\t\t/* If val == 0, product of val and each element in nums2 will be 0. And if midval>=0, \n\t\t\tthen because all products are 0, all products will be smaller or equal to midval. \n\t\t\tSo we can add all products in the answer */\n\t\t\tif(val==0 && midval>=0){\n                cnt+=nums2.size();\n            }\n            else if(val>0){\n                cnt+=maximiseSmall(nums2,val,midval);\n            }\n            else if(val<0){\n                cnt+=maximiseLarge(nums2,val,midval);\n            }\n        }\n        return cnt>=k;\n    }\n    \n    long long kthSmallestProduct(vector<int>& nums1, vector<int>& nums2, long long k) {\n        long long low=-1e10;\n        long long high=1e10;\n        long long res=0;\n        while(low<=high){\n            long long mid=(high+low)/2;\n            if(isPossible(nums1,nums2,mid,k)==true){\n                res=mid;\n                high=mid-1;\n            }\n            else{\n                low=mid+1;\n            }\n        }\n        return res;\n    }\n};\n```
['C', 'Binary Tree']