[Java][dp][recursion] seems simple
\nclass Solution {\n    //dp[i] is maximum earning starting from ith ride\n    public static long dp[];\n    public long maxTaxiEarnings(int n, int[][] rides) {
```\nclass Solution {\n    //dp[i] is maximum earning starting from ith ride\n    public static long dp[];\n    public long maxTaxiEarnings(int n, int[][] rides) {\n        //Sort based on start point\n        Arrays.sort(rides, (a,b)->a[0] - b[0]);\n        dp = new long[rides.length];\n        Arrays.fill(dp, -1);\n        return maxTaxiEarningsHelper(n, rides, 0);\n    }\n    \n    public long maxTaxiEarningsHelper(int n, int[][] rides, int start) {\n        if(start >= rides.length) {\n            return 0;\n        }\n        if(dp[start] != -1) {\n            return dp[start];\n        }\n        long earn = (rides[start][1] - rides[start][0]) + rides[start][2];\n        long pick = earn;\n        for (int i=start+1;i<rides.length;i++) {\n            if(rides[i][0] >= rides[start][1]) {\n                //next eligible ride is ith ride\n                pick += maxTaxiEarningsHelper(n, rides, i);\n                break;\n            }\n        }\n        //pick the next ride\n        long nonpick = maxTaxiEarningsHelper(n, rides, start + 1);\n        dp[start] = Math.max(nonpick, pick);\n        return dp[start];\n    }\n}\n```\n\n
[]