From brute force backtracking to efficient Two pointer solution
Bactracking solution - TLE\n\nclass Solution {\n    int count = 0;\n    int modulo = (int)Math.pow(10, 9) + 7;\n    public int numSubseq(int[] nums, int target)
Bactracking solution - TLE\n```\nclass Solution {\n    int count = 0;\n    int modulo = (int)Math.pow(10, 9) + 7;\n    public int numSubseq(int[] nums, int target) {\n        Arrays.sort(nums);\n        backtrack(new ArrayList<Integer>(), nums, target, 0);\n        return count%modulo;\n    }\n    \n    private void backtrack(List<Integer> list, int[] nums, int target, int start) {\n        if(list.size() != 0) {\n            if(list.get(0) + list.get(list.size()-1) <= target) {\n                count = (count + 1) % modulo;   \n            }\n        }\n        \n        for(int i=start;i<nums.length;i++) {\n            list.add(nums[i]);\n            backtrack(list, nums, target, i+1);\n            list.remove(list.size()-1);\n        }\n    }\n}\n```\n\nTwo pointer Solution:\n\n```\nclass Solution {\n    int modulo = (int)Math.pow(10, 9) + 7;\n    public int numSubseq(int[] nums, int target) {\n        Arrays.sort(nums);\n        int count = 0;\n        int[] dp = new int[nums.length];\n        dp[0] = 1;\n        for(int i=1;i<nums.length;i++) {\n            dp[i] = (dp[i-1]*2) % modulo;\n        }\n        \n        int lo = 0, hi = nums.length-1;\n        while(lo<=hi) {\n            if(nums[lo] + nums[hi] <= target) {\n                count = (count + dp[hi-lo++]) % modulo;\n            } else {\n                hi--;\n            }\n        }\n        \n        return count;\n    }\n    \n}\n```
[]