LC 2905 - Find Indices With Index and Value Difference II
[translate by ChatGPT] Although my algorithm was already O(n), I realized I was doing a lot of unnecessary work during the process. I didn’t actually need to compute the maximum and minimum for every previous position. As soon as I find a valid answer, I can return immediately, which saves a lot of time. I don’t need to store the maximum number itself — I can just keep track of the index and look it up later. I suspect using a vector to store extra values introduces some overhead. ...