Binary search
\n\nclass Solution {\n    //function for counting valid elements whose product with elements of second vector(nums2) is less than or equal to val when the eleme
\n```\nclass Solution {\n    //function for counting valid elements whose product with elements of second vector(nums2) is less than or equal to val when the element of first vector(nums1) is negative\n    int getvalue1(long long x,vector<int>& nums2,int m,long long val){\n        int l = 0 ,r = m - 1;\n        int ans = m;\n        while( l <= r){\n            int mid = l + (r-l)/2;\n            if(x *1LL* nums2[mid] <= val){\n                ans = mid;\n                r = mid -1;\n            }\n            else\n                l = mid + 1;\n        }\n        return m - ans;\n    }\n    //function for counting valid elements whose product with elements of second vector(nums2) is less than or equal to val when the element of first vector(nums1) is positive\n    int getvalue2(long long x,vector<int>& nums2,int m,long long val){\n        int l = 0 ,r = m - 1;\n        int ans = 0;\n        while( l <= r){\n            int mid = l + (r-l)/2;\n            if(x *1LL* nums2[mid] <= val){\n                ans = mid +1;\n                l = mid +1;\n            }\n            else\n                r = mid - 1;\n        }\n        return ans;\n    }\n    \n    bool valid(vector<int>& nums1, vector<int>& nums2,int n ,int m,long long mid,long long  k){\n        long long  ans = 0;\n        //counting the valid pairing of each element of first vector(nums1) with the elements of second vector(nums2)\n        for(int i = 0 ; i < n ; i++){\n            if(nums1[i] < 0)\n            ans += getvalue1(nums1[i],nums2,m,mid);\n            else\n            ans +=getvalue2(nums1[i],nums2,m,mid);\n        }\n        return ans >= k;\n    }\npublic:\n    long long kthSmallestProduct(vector<int>& nums1, vector<int>& nums2, long long k) {\n        \n        int n = nums1.size() , m = nums2.size() ;\n        long long ans = 0;\n        long long  mini = min(nums1[0],nums2[0]),maxi = max(nums1[n - 1],nums2[m - 1]);\n        long long l = min(mini*maxi,mini),r=max(mini*mini,maxi*maxi);\n        while(l <= r){\n            \n            long long mid = l + (r - l)/2;\n           \n            if(valid(nums1,nums2,n,m,mid,k)){\n                ans = mid ;\n                r = mid - 1;\n            }\n            else\n                l = mid + 1;\n        }\n        return ans;\n    }\n};\n```
['Binary Tree', 'C++']