C++ Precomputed Pow
Similar to the other solutions, but with precomputing power of 2 modulo 10 ^ 9 + 7.\n\nWell, Python folks are in luck. In C++, computing 2 ^ n inline gives TLE.
Similar to the other solutions, but with precomputing power of 2 modulo `10 ^ 9 + 7`.\n\nWell, Python folks are in luck. In C++, computing `2 ^ n` inline gives TLE. I could not find an efficient modulo power function. So, I just precomputed the `pow(i, 2) % mod` values iterativelly.\n\n```cpp\nint numSubseq(vector<int>& nums, int target) {\n    int res = 0, mod = 1000000007;\n    vector<int> pre = {0, 1};\n    for (auto i = pre.size(); i <= nums.size(); ++i)\n        pre.push_back((pre.back() << 1) % mod);       \n    sort(begin(nums), end(nums));\n    for (int i = 0, j = nums.size() - 1; i <= j; ++i) {\n        while (i <= j && nums[i] + nums[j] > target)\n            --j;\n        res = (res + pre[j - i + 1]) % mod;\n    }\n    return res;\n}\n```
[]