Self explanatory intuitive C++ code
\nusing ll=long long;\nclass Solution {\npublic:\n    // This returns TRUE, iff the number of elements in the set(A)*set(B) <= \'val\' is >= \'K\' \n    bool pr
```\nusing ll=long long;\nclass Solution {\npublic:\n    // This returns TRUE, iff the number of elements in the set(A)*set(B) <= \'val\' is >= \'K\' \n    bool predicate(ll val, const ll K, vector<int>& A, vector<int>& B){\n        ll cnt=0;\n        for(auto a:A){\n            if(a<0){\n                cnt += findNumberOfNumbersLessThanEqualToValInNonIncreasingArray(val,\n                                                                                B,a);\n            } else if (a==0) {\n                if (val>=0) cnt+=B.size();\n            } else if (a>0) {\n                cnt += findNumberOfNumbersLessThanEqualToValInNonDecreasingArray(val,\n                                                                                B,a);\n            }\n        }\n        return cnt>=K;\n    }\n    \n    int findNumberOfNumbersLessThanEqualToValInNonIncreasingArray(const ll val,\n                                                                  vector<int>& B,\n                                                                 const int a){\n        // find the smallest index for which B[i]<=val\n        int n = B.size();\n        int lo=0,hi=n-1;\n        // if the smallest numebr is > val, then there is no such element\n        if((ll)B[hi]*a > val)return 0;\n        while(lo!=hi){\n            int mid=lo+(hi-lo)/2;\n            if((ll)B[mid]*a <= val)hi=mid;\n            else lo=mid+1;\n        }\n        return n-lo;\n    }\n    \n    int findNumberOfNumbersLessThanEqualToValInNonDecreasingArray(const ll val,\n                                                                  vector<int>& B,\n                                                                 const int a){\n        // find the largest index for which B[i]<=val\n        int n = B.size();\n        int lo=0,hi=n-1;\n        // if the smallest value if > val, then there is no such elements present\n        if((ll)B[lo]*a > val) return 0;\n        while(lo!=hi){\n            int mid=lo+(hi-lo+1)/2;\n            if((ll)B[mid]*a <= val)lo=mid;\n            else hi=mid-1;\n        }\n        return lo+1;\n    }\n    \n    long long kthSmallestProduct(vector<int>& A, vector<int>& B, long long K) {\n        // if x=A[i]*B[j], then we need to find the set of \'x\'(s) for which number of numbers <= \'x\'  will be >= \'K\' ans choose smallest in that set(smallest \'x\')\n        \n        ll lo=-1e10-100;\n        ll hi=1e10+100;\n        \n        while(lo!=hi){\n            ll mid=lo+(hi-lo)/2;\n            if(predicate(mid,K,A,B))hi=mid;\n            else lo= mid+1;\n        }\n        \n        // since k <= A.length * B.length as given in the question, Here no need to check whetehr the answer exists or not\n        \n        return lo;\n    }\n};\n```
['Array', 'Binary Tree']