← Oracle Interview Insights

Oracle·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Oracle SWE interview with a classic two-pointer problem. Nothing too wild but the O(n) constraint meant you had to know exactly what you were doing, no brute force handwaving.

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. Solve it in O(n) time.

Algorithms & Data Structures
Author's notes

The O(n) requirement is what makes this non-trivial.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: the container's area is determined by the shorter line and the distance between lines. Use a two-pointer technique starting from the widest possible container and moving inward, always moving the pointer at the shorter line, to achieve O(n) time.

Pro tip: Explain why moving the shorter line is safe: any container formed with the shorter line and a closer line will have less width and no greater height, so it cannot be better. This demonstrates deep understanding and avoids brute-force.

1. Clarify the problem

Restate the problem: 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 checking all pairs takes O(n^2) time, which is inefficient for large inputs. This sets the stage for the optimal solution.

3. Introduce two-pointer technique

Initialize two pointers at the beginning and end of the array. Compute the area and update the maximum. Then move the pointer pointing to the shorter line inward, because the width decreases and the height is limited by the shorter line.

4. Explain correctness and complexity

Argue that moving the shorter pointer is safe: any other container involving that shorter line and a closer line will have less width and no greater height, so it cannot yield a larger area. The algorithm runs in O(n) time and O(1) space.

5. Walk through an example

Trace the algorithm on a small example, such as [1,8,6,2,5,4,8,3,7], to demonstrate how the maximum area is found and to verify the logic.

Key Points to Mention

  • Area formula: min(height[i], height[j]) * (j - i)
  • Two-pointer approach: start with left=0, right=n-1
  • Move the pointer at the shorter line inward
  • Proof of correctness: moving the shorter line cannot miss a larger area
  • Time complexity: O(n), space complexity: O(1)
  • Edge cases: empty array, two elements, all equal heights

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