✅ C++ Simple Binary Search Solution with comments | Easy to understand
We can\'t apply priority queue over here just because of the constraints, that would give us TLE.\nBut we can apply Binary Search over here.\n\nApproach\nWe can
We can\'t apply priority queue over here just because of the constraints, that would give us TLE.\nBut we can apply *Binary Search* over here.\n\n**Approach**\nWe can apply the Binary search over the range [-1e10,1e10] (minimum product of the pairs,maximum product of the pairs).We can count the number of pair products and decrease our search space accordingly\n\nNow the question arises, how can we count the number of pair products without getting tle?\nThe answer is, we can apply Binary search here as well.\n\n**Keep this in mind -** There can be negative elements also and when we consider the negative element the logic got reversed.\n\n**C++ Code**\n```\nclass Solution {\npublic:\n    long long countSmallerProducts(vector<int>& nums1, vector<int>& nums2, long long product){\n        long long count=0;\n        for(int num:nums1){\n            if(num>=0){\n                int l=0,h=nums2.size()-1,temp=-1;\n                while(l<=h){\n                    int mid=l+(h-l)/2;\n                    if((long long)num*nums2[mid] <= product){\n                        temp=mid;\n                        l=mid+1;\n                    }else h=mid-1;\n                }\n                count+=temp+1;\n            }else{\n                int l=0,h=nums2.size()-1,temp=nums2.size();\n                while(l<=h){\n                    int mid=l+(h-l)/2;\n                    if((long long)num*nums2[mid] <= product){\n                        temp=mid;\n                        h=mid-1;\n                    }else l=mid+1;\n                }\n                count+=(nums2.size()-temp);\n            }\n        }\n        return count;\n    }\n    long long kthSmallestProduct(vector<int>& nums1, vector<int>& nums2, long long k) {\n        long long s=-1e10,e=1e10,ans=0;\n        \n        \n        while(s<=e){\n            long long mid = (s+e)/2;\n            if(countSmallerProducts(nums1,nums2,mid)>=k){\n                ans=mid;\n                e=mid-1;\n            }else s=mid+1;\n        }\n        \n        return ans;\n    }\n};\n```
['C', 'Binary Tree']