fork download
  1. def maxArea(height):
  2. left = 0
  3. right = len(height) - 1
  4. max_area = 0
  5.  
  6. while left < right:
  7. width = right - left
  8. current_height = min(height[left], height[right])
  9. current_area = width * current_height
  10. max_area = max(max_area, current_area)
  11.  
  12. if height[left] < height[right]:
  13. left += 1
  14. else:
  15. right -= 1
  16.  
  17. return max_area
  18.  
  19. # Test case execution
  20. test_case = [1, 8, 6, 2, 5, 4, 8, 3, 7]
  21. result = maxArea(test_case)
  22. print(f"Test case output: {result}") # Output: Test case output: 49
Success #stdin #stdout 0.13s 14044KB
stdin
Standard input is empty
stdout
Test case output: 49