Image Explanation🏆- [Binary Exponentiation || Two Pointers || Pre-Computation] - C++/Java/Python
Video Solution (Aryan Mittal) - Link in LeetCode Profile\nNumber of Subsequences That Satisfy the Given Sum Condition by Aryan Mittal\n\n\n\n# Approach & Intuti
# Video Solution (`Aryan Mittal`) - Link in LeetCode Profile\n`Number of Subsequences That Satisfy the Given Sum Condition` by `Aryan Mittal`\n![lc.png](https://assets.leetcode.com/users/images/9bfb5b4d-5bca-4a80-a9dd-ee595173341f_1683338481.6511838.png)\n\n\n# Approach & Intution\n![image.png](https://assets.leetcode.com/users/images/fbca2324-1293-4396-bc9c-2dbe90822e0e_1683337685.211683.png)\n![image.png](https://assets.leetcode.com/users/images/96adf4c9-9b58-4c58-ba2b-4a369f5f404f_1683337701.119572.png)\n![image.png](https://assets.leetcode.com/users/images/251f9159-819d-4ff2-93f1-5fcd425c9d4f_1683337711.565151.png)\n![image.png](https://assets.leetcode.com/users/images/56f1664b-82f1-41ab-9719-3e5442379bb2_1683337721.7740104.png)\n\n\n# How to Code in Different ways\n![image.png](https://assets.leetcode.com/users/images/4f181dfb-67fd-4e7f-a835-05faa28b455c_1683337759.7798407.png)\n![image.png](https://assets.leetcode.com/users/images/33227fb3-fc12-4821-b094-ac0f2eb25dc6_1683337769.2874224.png)\n![image.png](https://assets.leetcode.com/users/images/8324f714-7b16-4179-a125-b2c360b7a4cb_1683337775.951145.png)\n![image.png](https://assets.leetcode.com/users/images/eb8d42c9-5765-4028-b3e2-6ef7c3426c59_1683337784.789647.png)\n![image.png](https://assets.leetcode.com/users/images/edc5e67d-9d95-46af-87c3-79ab1e68df45_1683337792.1496615.png)\n![image.png](https://assets.leetcode.com/users/images/005a09f7-6a51-4dd6-96c8-cbb970850777_1683337808.316917.png)\n![image.png](https://assets.leetcode.com/users/images/f44f8803-525f-46c4-8409-43443f71d762_1683337821.069586.png)\n\n\n\n# Code\n```C++ []\nclass Solution {\npublic:\n    int numSubseq(vector<int>& nums, int target) {\n        int res = 0, mod = 1000000007, l = 0, r = nums.size() - 1;\n        vector<int> pre = {1};\n        for (auto i = 1; i <= nums.size(); ++i)\n            pre.push_back((pre.back() << 1) % mod);   \n                \n        sort(begin(nums), end(nums));\n        \n        while (l <= r) {\n            if (nums[l] + nums[r] > target) {\n                r--;\n            } else {\n                res = (res + pre[r - l++]) % mod;\n            }\n        }\n\n        return res;\n    }\n};\n```\n```Java []\nclass Solution {\n    public int numSubseq(int[] nums, int target) {\n        int res = 0, mod = 1000000007, l = 0, r = nums.length - 1;\n        List<Integer> pre = new ArrayList<>();\n        pre.add(1);\n        for (int i = 1; i <= nums.length; ++i) {\n            pre.add((pre.get(i - 1) << 1) % mod);\n        }\n\n        Arrays.sort(nums);\n\n        while (l <= r) {\n            if (nums[l] + nums[r] > target) {\n                r--;\n            } else {\n                res = (res + pre.get(r - l++)) % mod;\n            }\n        }\n\n        return res;\n    }\n}\n```\n```Python []\nclass Solution:\n    def numSubseq(self, nums: List[int], target: int) -> int:\n        res, mod = 0, 1000000007\n        l, r = 0, len(nums) - 1\n        pre = [1]\n        for i in range(1, len(nums) + 1):\n            pre.append((pre[-1] << 1) % mod)\n                \n        nums.sort()\n        \n        while l <= r:\n            if nums[l] + nums[r] > target:\n                r -= 1\n            else:\n                res = (res + pre[r - l]) % mod\n                l += 1\n\n        return res\n```
['Array', 'Two Pointers', 'C++', 'Java', 'Python3']