Classical "Weighted Job Scheduling" problem | [JS] [DP,Binary Search]
\n// Same as https://leetcode.com/problems/maximum-profit-in-job-scheduling/\n// Time -> O(nlogn), where n = length of rides array\n// Space -> O(n), where n = 
```\n// Same as https://leetcode.com/problems/maximum-profit-in-job-scheduling/\n// Time -> O(nlogn), where n = length of rides array\n// Space -> O(n), where n = length of rides array\n\n/**\n * @param {number} n\n * @param {number[][]} rides\n * @return {number}\n */\nvar maxTaxiEarnings = function(n, rides) {\n    \n    const len = rides.length\n    \n    rides.sort((a,b) => {\n        return a[1] - b[1]\n    })\n    \n    // Binary search\n    function binarySearch(idx) {\n        let low = 0, high = idx\n        \n        while(low < high) {\n            let mid = Math.trunc((low+high)/2)\n            \n            if(rides[mid][1] <= rides[idx][0]) low = mid+1\n            else high = mid\n        }\n        \n        return high === 0 ? -1 : high-1\n    }\n    \n    let dp = new Array(len).fill(0)\n    dp[0] = rides[0][2] + (rides[0][1] - rides[0][0])\n    \n    for(let i=1; i<len; i++) {\n        dp[i] = rides[i][2] + (rides[i][1] - rides[i][0])\n        let j = binarySearch(i)\n        \n        if(j !== -1)\n            dp[i] += dp[j]\n        \n        dp[i] = Math.max(dp[i], dp[i-1])\n    }\n    \n    return dp[len-1]\n};\n```
['JavaScript']