← All questions
MediumCoding

Container With Most Water

Asked atOraclePaytmSliceTruemeds
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Start with the widest possible container using the first and last lines.
  2. 02Compute area as width times the shorter of the two heights.
  3. 03Move the pointer at the shorter line because keeping it cannot improve area as width shrinks.
  4. 04Track the best area until the pointers meet.

Reference answer

Then expect these follow-ups

  • Why can keeping the shorter line never produce a better area after width decreases?

    Tests: greedy proof

  • Does the same pointer rule work for trapping rain water? Why or why not?

    Tests: pattern discrimination

Hiring now

Paytm has 128 open roles right now

Also hiring: Slice

landed applies to roles like these for you, on each company’s own site, with answers written for the role.

Get 5x interviews10 free auto-applies. No card.
  • Senior Software Engineer – Backend (Travel)

    Bangalore, Karnataka

  • Junior Marketing Manager

    Luxembourg

  • Collection Manager- North- Business- Lending Collections

    Aligarh, Uttar Pradesh

Or practice this question first

Next question