I had an interview question which was find the total sum of all of the max-min of every subarray
I know the brute force is a nested loop (o^2)
What are the better approaches to solving this? Thanks in advance