Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

What is the maximum area of water a container can hold between two bars of heights [1, 8, 6, 2, 5, 4, 8, 3, 7] (area = min(height) times distance between indices)?

  1. A. 42
  2. B. 28
  3. C. 49
  4. D. 64

Correct answer: C. 49

Two pointers move the shorter side inward, because the shorter line limits the area and no better partner exists for it. The optimum here is between heights 8 and 7 at distance 7.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic