
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
If you simulate the problem, it will be O(n^2) which is not efficient.
Try to use two-pointers. Set one pointer to the left and one to the right of the array. Always move the pointer that points to the lower line.
How can you calculate the amount of water at each step?