Apple interview #4 Sum of Two Numbers in a Sorted Array — Two-Pointer Pattern (Interview Prep | Array)

21 Views
No Comments

You are given a sorted array of 10 elements.
Given a target number, find two distinct elements in the array whose sum equals the target.

Example array

Arr = {1, 3, 6, 9, 11, 14, 16, 19, 23, 27}

Input: a target value T.
Output: any pair (x, y) from Arr such that x + y = T (or report that no such pair exists).

Classic two-sum in a sorted array. Apply the two-pointer technique: start at both ends, move the pointers inward based on the sum, and return when it matches the target. Time O(n), space O(1). Keywords: interview prep, two-pointer, array, two-sum.

The VOprep team has long accompanied candidates through various major company OAs and VOs, including Apple, Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for Tiktok or similar engineering-focused companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.

END
 0