← Oracle Interview Insights

Oracle·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Oracle SWE coding round, basically one algorithmic problem the whole time. Classic container with most water, but they wanted O(n) specifically so you couldn't brute force your way through it.

Questions Asked (1)

Q1

Given an array of integers representing heights of vertical lines, find the two lines that form a container holding the maximum amount of water. Must be solved in O(n) time.

Algorithms & Data Structures
Author's notes

The O(n) constraint is what makes this worth thinking about.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and confirming that the container's area is determined by the shorter line and the distance between lines. Then explain the two-pointer technique: initialize pointers at both ends, compute the area, and move the pointer pointing to the shorter line inward, repeating until pointers meet. Emphasize that this yields O(n) time and O(1) space.

Pro tip: During the explanation, explicitly state why moving the shorter line is safe: any container formed with the shorter line and any other line cannot exceed the current area because the height is limited by the shorter line and the width will be smaller. This demonstrates deep understanding and avoids the common pitfall of moving the taller line.

1. Clarify the problem

Restate the problem to ensure understanding: given an array of heights, find two lines that together with the x-axis form a container holding the most water. Confirm that the container cannot be slanted and that the area is min(height[i], height[j]) * (j - i).

2. Discuss brute force and its limitations

Mention that a brute force approach would check all pairs in O(n^2) time, which is inefficient for large inputs. This sets the stage for the need for an O(n) solution.

3. Introduce the two-pointer technique

Explain that we can use two pointers, one at the beginning and one at the end of the array. The area is computed as the minimum of the two heights multiplied by the distance between them.

4. Explain the greedy pointer movement

After computing the area, move the pointer that points to the shorter line inward. Justify this by noting that moving the taller line cannot increase the area because the height is limited by the shorter line and the width decreases.

5. Analyze complexity and edge cases

Conclude that the algorithm runs in O(n) time and O(1) space. Mention edge cases such as arrays with fewer than two elements or all equal heights, and confirm the algorithm handles them correctly.

Key Points to Mention

  • Area formula: min(height[i], height[j]) * (j - i)
  • Two-pointer initialization at both ends
  • Greedy movement: always move the pointer with the smaller height
  • Proof of correctness: moving the shorter line is safe because any other container with that line will have a smaller width and thus cannot exceed the current maximum
  • Time complexity: O(n) because each element is visited at most once
  • Space complexity: O(1) as only constant extra space is used

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.