Java Solution | Bottom-Up DP
\nclass Solution {\n    public long maxTaxiEarnings(int n, int[][] rides) {\n        // sort by ride end\n        Arrays.sort(rides, (r1, r2) -> Integer.compare
```\nclass Solution {\n    public long maxTaxiEarnings(int n, int[][] rides) {\n        // sort by ride end\n        Arrays.sort(rides, (r1, r2) -> Integer.compare(r1[1], r2[1]));\n        int next = 0;\n        long[] dp = new long[n+1];\n        for (int i = 1; i < n+1; ++i) {\n            dp[i] = dp[i-1];\n\t\t\t// iterate through rides with the same end\n            while (next < rides.length && i == rides[next][1]) {\n                var ride = rides[next];\n                dp[i] = Math.max(dp[i], dp[ride[0]] + ride[1] - ride[0] + ride[2]);\n                next++;\n            } \n        }\n        return dp[n];\n    }\n}\n```
[]