java commented code.
```\npublic long maxTaxiEarnings(int n, int[][] rides) {\n        int num = rides.length;\n        int[][] jobs = new int[num][3];\n        for (int i = 0; i < 
```\npublic long maxTaxiEarnings(int n, int[][] rides) {\n        int num = rides.length;\n        int[][] jobs = new int[num][3];\n        for (int i = 0; i < num; i++) {\n            jobs[i] = new int[] {rides[i][0], rides[i][1], rides[i][1] - rides[i][0] + rides[i][2]};\n        }\n        Arrays.sort(jobs, (a, b)->a[1] - b[1]);\n\t\t\n\t\t// create a treemap that contain only max "earning" we get till current "endtime"\n\t\t// TreeMap<endTime, earning>\n        TreeMap<Integer, Long> dp = new TreeMap<>();\n        dp.put(0, 0L);\n        for (int[] job : jobs) {\n\t\t\n\t\t    // find what is max earning acheived before startTime of current job and add current earning\n            Long cur = dp.floorEntry(job[0]).getValue() + job[2];\n            if (cur > dp.lastEntry().getValue())\n\t\t\t\t\n\t\t\t\t//if new cur is max than the top earning in treemap than add new earning \n                dp.put(job[1], cur);\n        }\n\t\t\n\t\t//finally return the top value which is max earning\n        return dp.lastEntry().getValue();\n\n    }\n\t\n\t\n\tSimilar Problem:\n\t[1235. Maximum Profit in Job Scheduling](https://leetcode.com/problems/maximum-profit-in-job-scheduling/)
['Tree', 'Sorting', 'Java']