Answer: Snowflake OA Question 2024 September | Two Pointers | on-campus
Answer · Posted Jun 2026
Solution: Container With Most Water — Greedy Two Pointers Approach A brute force O(N²) approach tries all pairs, but we can solve this in O(N) using Two Pointers. We start with the widest possible container (left at 0, right at n-1). At each step, the water held is min(height[left], height[right]) * (right - left). The key greedy insight is: Moving the pointer pointing to the shorter line inward is the only way that could possibly increase the area (the width ...
The full answer & interview discussion are available to premium members.
Log in Create a free account