Top Down DP | Binary Search [Python]
\nclass Solution:\n    def maxTaxiEarnings(self, n: int, rides: List[List[int]]) -> int:\n        dp={}\n        rides.sort(key=lambda x:x[0]) #sorting based on
```\nclass Solution:\n    def maxTaxiEarnings(self, n: int, rides: List[List[int]]) -> int:\n        dp={}\n        rides.sort(key=lambda x:x[0]) #sorting based on start points\n        def recurse(i):\n            if(i>=len(rides)):return 0 #no other taxi rides left\n            if(i in dp):return dp[i]\n            x=recurse(i+1) #not considering i\'th ride\n            #binary searching for the value in right of i to find the next ride\n            l=i\n            r=len(rides)\n            while(l<r):\n                mid=(l+r)//2\n                if(rides[mid][0]>=rides[i][1]):\n                    r=mid\n                else:\n                    l=mid+1\n            x=max(x,rides[i][1]-rides[i][0]+rides[i][2]) #considering i as last element\n            x=max(x,recurse(r)+rides[i][1]-rides[i][0]+rides[i][2]) #considering i and next ride\n            dp[i]=x\n            return x\n        return fun(0)\n```\n
[]