Data Structures & AlgorithmsHardFlipkart/Uber OA · placement

Lines of heights [9, 5, 3, 2, 4, 9, 1, 2, 9] stand at x = 0, 1, …, 8. Two pointers find the pair of lines that, with the x-axis, holds the most water (area = min(h[i], h[j]) × (j − i)). What is that maximum area?

  1. A. 72
  2. B. 71
  3. C. 37
  4. D. 8

Correct answer: A. 72

Start with the widest pair and always move the pointer at the shorter line inward (the taller one cannot do better with a narrower width). The best area is 72.

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

Exams that ask this topic