Question bankPricingSign in

Container Capacity

Two PointersMedium1:30

You are given an array of positive integers where each element represents the height of a vertical wall. Two walls and the x-axis form a container that can hold water. Find the pair of walls that can hold the most water.

For example, given heights [1, 8, 6, 2, 5, 4, 8, 3, 7], the maximum water the container can hold is 49 (between the walls of height 8 at index 1 and height 7 at index 8).

Explain your approach, walk through the algorithm step by step, and analyze the time and space complexity.

How to approach it

  • Hint 1

    Think about what happens when you start with the widest possible container.

  • Hint 2

    If you have two pointers at each end, which pointer should you move inward and why?

  • Hint 3

    The shorter wall is always the bottleneck -- moving the taller wall can never increase capacity.

Ready to answer it out loud?

Record your answer in 1:30 and Preptile scores it 1–10 with specifics — what landed, what you skipped, and what to say next time.

Practising needs an invite code. Join the waitlist and we’ll send you one.