✅ C++ | 2 pointers Simple Explanation
As we care about only min & max of a subseq ... we need not bother about the ordering of elems . so just sort the array and apply two pointers to count subseq t
**As we care about only min & max of a subseq ... we need not bother about the ordering of elems . so just sort the array and apply two pointers to count subseq that has the i\'th elem as minimum and j\'th elem as the maximum**\n\n**proof :**\n```\n/*\n [3 5 6 6]\n i       j\nsay  i at 3 and j at 6.. rem 3 elem after 3 are 5,6,6\n\nTotal  subseq having elems from [i,j] = 2 power(j-i) \nbelow are possible  subseq that includes ith elem :\n\n1 len = (3)  need 0 more from rem 3 elem (5,6,6)=> 3c0  = 1\n2 len = (3,5)  (3,6)  (3,6)     => 1 from rem 3 => 3c1 = 3\n3 len = (3,5,6) (3,5,6) (3 6 6) => 2 from rem 3 => 3c2  = 3 \n4 len = (3,5,6,6)               => 3 from rem 3 => 3c3 = 1\n\nwe know  Nc0 + Nc1 + Nc2..+NcN = 2^N\n\n*/\n\nclass Solution {\npublic: int mod = 1e9+7;\n    int numSubseq(vector<int>& a, int k) {\n        vector<int> twopower{1}; //precompute pow of 2 \n        \n        for(int i = 0;i<a.size();i++){\n            twopower.push_back((twopower.back()*2)%mod);\n        }\n        \n        sort(begin(a),end(a)); int ans = 0;\n        \n        int i = 0,j = a.size()-1; \n        \n        while(i<=j){\n            \n            if(a[i]+a[j]>k){\n                j--;\n            }\n            else{\n                int rem = j-i,r = 0;\n                ans = (ans + twopower[rem]) % mod;\n                i++;\n            }\n        }\n        return ans;\n    } \n};\n```
['Two Pointers', 'C']