Getting a TLE for test case #1

your code time complexity is O(n^2)
your can optimise it by removing inner loop
try to think how you can optimise it??

hint:
calculate max diff in y in O(n)
now traverse in the array and calculate max diff in x along with max area