This one didn’t go very well. This was my solution:
This is like, at least a 50 minute solution. I DID get a working solution after 30 minutes, but it timed out. I thought I could weasel my way out of O(n^2) complexity with Math.max, but that’s obviously still a for loop. That was sort of wishful thinking.
So my second implementation didn’t fix much.
Claude gave me this incredibly simple solution:
Let me walk through it with comments:
So looking at Claude’s answer, it’s like I was stuck in this “looking forwards” paradigm. But there was this looking backwards option the whole time and I was too stuck in my O(n2) bullshit to realize it.
The difference has TWO sides - it requires a high number farther up, and a lower number farther down. We’re looking, fundamentally, for the largest range, as long as that range goes low high in the same direction as the array progresses.