All practice tasks

Coding (Algo)

Find the Widest Supported Container

Two pointers · Medium

A geometric planning tool models vertical supports one unit apart. Choosing two supports defines a container whose usable height is limited by the shorter support. Intermediate supports do not reduce its area; this is not a trapped-rainwater calculation.

Return the largest area defined by any two distinct supports in the supplied height sequence.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

{ heights: integer[] }

Fields

  • heights contains non-negative integer heights. Support i is at horizontal position i.

Output

Return value

  • For indexes i < j, area is min(heights[i],heights[j]) * (j - i). Return the largest area.
  • Return 0 when fewer than two supports exist. Return area, not indexes or total water between every pair.

Constraints

  • 0 <= heights.length <= 100000; 0 <= heights[i] <= 1000000000.
  • Every area fits exactly in a safe JSON integer.

Examples

Example 1

{
  "heights": [
    1,
    8,
    6,
    2,
    5,
    4,
    8,
    3,
    7
  ]
}

Returns

49

Example 2

{
  "heights": [
    5,
    5
  ]
}

Returns

5

Required complexity

O(n) time and O(1) auxiliary space

What this task practices

Find the Widest Supported Container is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as medium difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.