Java 🔥| | Python 🔥| | Memoization 🔥
## Please don\'t forget to upvote. \u2B06\uFE0F\n---\n# Code \njava []\nclass Solution {\n    int mod = 1000000007;\n    public int recursiveFunction(int[] loca
>  ## *Please don\'t forget to upvote.* \u2B06\uFE0F\n---\n# Code \n```java []\nclass Solution {\n    int mod = 1000000007;\n    public int recursiveFunction(int[] locations,int start,int finish,int fuel,int[][] dp)\n    {\n        if(fuel < 0)    return 0;\n        if(dp[start][fuel] !=-1)    return dp[start][fuel];\n        int ans = 0;\n        if(start == finish) ans++;\n        for(int i = 0;i<locations.length;i++)\n        {\n            if(i == start || Math.abs(locations[i]-locations[start]) > fuel) continue;\n            ans+=recursiveFunction(locations,i,finish,fuel-Math.abs(locations[i]-locations[start]),dp);\n            ans%=mod;\n        }\n        dp[start][fuel] = ans;\n        return ans;\n    }\n    public int countRoutes(int[] locations, int start, int finish, int fuel)\n    {                                                                           \n        int[][] dp = new int[locations.length][fuel+1];\n        for(int i = 0;i<dp.length;i++)\n        {\n            for(int j = 0;j<dp[0].length;j++)\n            {\n                dp[i][j] = -1;\n            }\n        }\n        return recursiveFunction(locations,start,finish,fuel,dp);               \n    }\n}\n```\n\n\n```python []\nclass Solution:\n    def recursiveFunction(self,locations,start,finish,fuel,dp):\n        if fuel<0:\n            return 0\n        if dp[start][fuel] !=-1:\n            return dp[start][fuel]\n        ans = 0\n        if start == finish:\n            ans = 1\n        for i in range(len(locations)):\n            if i == start or abs(locations[i]- locations[start]) > fuel:\n                continue\n            ans+=self.recursiveFunction(locations,i,finish,fuel-abs(locations[i]-locations[start]),dp)\n            ans%=(int(1e9)+7)\n\n        dp[start][fuel] = ans\n        return ans\n\n    def countRoutes(self, locations: List[int], start: int, finish: int, fuel: int) -> int:\n\n        dp = [[-1 for i in range(fuel+1)] for j in range(len(locations))]\n\n        return self.recursiveFunction(locations,start,finish,fuel,dp)\n\n\n```\n---
['Dynamic Programming', 'Memoization', 'C++', 'Java', 'Python3']