DP with Sweep
Sort the rides and then process rides in order of their pick-up points. Track the max profit for each point in dp.\n\nSince we are using an array, we need to al
Sort the rides and then process rides in order of their pick-up points. Track the max profit for each point in `dp`.\n\nSince we are using an array, we need to also do the sweep to carry forward the max profit till the next pick-up point.\n\n**C++**\n```cpp\nlong long maxTaxiEarnings(int n, vector<vector<int>>& rides) {\n    long long dp[100001] = {}, pos = 0;\n    sort(begin(rides), end(rides));\n    for (const auto &r : rides) {\n        for (; pos < r[0]; ++pos)\n            dp[pos + 1] = max(dp[pos + 1], dp[pos]);\n        dp[r[1]] = max(dp[r[1]], dp[r[0]] + r[1] - r[0] + r[2]);\n    }\n    return *max_element(begin(dp), begin(dp) + n + 1);\n}\n```\n**Complexity Analysis**\n- Time: O(m log m), where `m` is the number of rides. This is under the assumption that `m log m` would be larger than `n`.\n- Memory: O(n) for tabulation.
[]