C++ | 2 Pointer with easy explanation | upvote if you liked the approach | O(nlogn) time complexity
\nclass Solution {\npublic:\n    int numSubseq(vector<int>& nums, int target) {\n        // sort the array, to get the right pairs optimally\n        sort(nums.
```\nclass Solution {\npublic:\n    int numSubseq(vector<int>& nums, int target) {\n        // sort the array, to get the right pairs optimally\n        sort(nums.begin(), nums.end());\n        int len = nums.size();\n        // take a temp array to store the number values, once taking the number and once ignoring it\n        int arrdp[len];\n        // using two pointer concept\n        int frontptr = 0;\n        int backptr = nums.size() - 1;\n        int totalsum = 0;\n        // allocate each eelement to 1\n        for(int i = 0; i < len; i++)\n            arrdp[i] = 1;\n        int MOD = 1000000007;\n        // now, keep checking for the values in the array.\n        for(int i = 1; i < len; i++){\n            arrdp[i] = arrdp[i - 1] * 2; // taking once the  current element and once rejecting the same element\n            if(arrdp[i] >= MOD)  // if overflow then reduce the value\n                arrdp[i] -= MOD;\n            \n        }\n        while(frontptr <= backptr){\n            // if the condition is true take it in the final ans\n            if(nums[frontptr] + nums[backptr] <= target){\n                totalsum += arrdp[backptr - frontptr];\n                frontptr++; // taking a pair we will increment the frontptr becuase it is already included\n                if(totalsum >= MOD) // if overflow then, reduce the value\n                    totalsum -= MOD;\n            }\n            // else drecrement the backptr as, we dont\'t need to include current element\n            else\n                backptr--;\n        }\n        return totalsum;\n    }\n};\n```
[]