BEST ANS EASIEST TWO POINTER APPROACH
Intuition\n Describe your first thoughts on how to solve this problem. \nTwo Pointer Approach as we have to make sure that our window\'s max-min<=target.\n\n# A
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTwo Pointer Approach as we have to make sure that our window\'s max-min<=target.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe have to sort the given nums array so that we can apply two pointer approach.For the window that has max-min<=target will have a length of r-l+1,but the first element should be included that is the minimum of window to have all the unique possible answers. Therefore for that window we can have 2^r-l valid subsequence because for every element in the window we can have 2 options to include it or not.\n\n![227f8612-ef0d-4067-ba45-b55caf71dd93.png](https://assets.leetcode.com/users/images/59edcf48-f5d5-4648-ac5b-fbfe97ebbc96_1683341650.2232242.png)\n![5c11d232-80de-4cf5-8753-da23f2f43c21.png](https://assets.leetcode.com/users/images/4918c004-2d98-4d66-b476-3876e6446fa7_1683341667.7920384.png)\n![16f660c1-2d14-4c0f-ab8e-144f522a2b4e.png](https://assets.leetcode.com/users/images/9d1fead2-8ddf-49df-9443-f8a1b428a786_1683341674.6181836.png)\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n```\nO(N*LOG(N))          Sorting takes N*log(n)  \n```\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n```\nO(N)\n```\n\n# Code\n```\nconst int MOD = 1000000007;\n\nclass Solution {\npublic:\n    int numSubseq(vector<int>& nums, int target) {\n        sort(nums.begin(), nums.end());\n        int ans = 0;\n        int l = 0, r = nums.size() - 1;\n        \n        vector<int>powerof2(nums.size());\n        powerof2[0] = 1;\n        for(int i = 1; i < nums.size(); i++) {\n            powerof2[i] = (powerof2[i-1] * 2)%MOD;\n        }\n        while(l <= r) {\n            if(nums[l] + nums[r] <= target) {\n                ans += powerof2[r - l];\n                ans %= MOD;\n                l++;\n            } else {\n                r--;\n            }\n        }\n\n        return ans;\n    }\n};\n```
['C++']