C++||DP with Binary Search with detailed comments
Please do upvote if found helpful\n\nclass Solution {\npublic:\n    \n   long long dp[100000];\n    \n    long long solve(vector<vector<int>>& pairs, int curr, 
**Please do upvote if found helpful**\n```\nclass Solution {\npublic:\n    \n   long long dp[100000];\n    \n    long long solve(vector<vector<int>>& pairs, int curr, int n){\n        if(curr>=n) return 0;\n        if(dp[curr]!=-1) return dp[curr];\n        long long op1=solve(pairs,curr+1,n);  //option 1 is to leave the current passenger\n        long long op2=pairs[curr][2];     //option 2 is to take the current passenger\n        long long tos=pairs[curr][1];    //if we are deciding to take the passenger then we need find the next passenger that we can pick (tos variable name here means toSearch)\n        long long s=curr;   //curr index is our starting index\n        long long e=n-1;  // n-1 is the last index\n        long long i=-1;\n        \n        while(s<=e){\n            long long mid=s+(e-s)/2;\n            if(pairs[mid][0]<tos){  // if the start time is less than the end time of the passenger we decided to pick then we can\'t pick this passenger\n                s=mid+1;\n            }else{\n                i=mid;         //updating i with possible index of the passenger we can pick, we need to get the first possible index\n                e=mid-1;\n            }\n        }\n        \n        if(i!=-1) op2+=solve(pairs,i,n);    // if i!=-1 implies we found a possuble passenger we can take, so we\'ll add the answer that we\'ll get from there\n        \n        return dp[curr]= max(op1,op2);  // returning the maximum of option 1 and option 2\n    }\n    \n\t\n    long long maxTaxiEarnings(int n, vector<vector<int>>& rides) {\n        memset(dp,-1,sizeof(dp));\n        int sz=rides.size();\n        vector<vector<int>> pairs;     // converting to a new vector with start, end and  profit\n        for(int i=0;i<sz;i++) pairs.push_back({rides[i][0],rides[i][1],(rides[i][1]-rides[i][0]+rides[i][2])}); \n        sort(pairs.begin(),pairs.end());   //sorting on the basis of start time\n        return solve(pairs,0,sz);\n        \n    }\n};\n```
[]