Apple面试题 #4有序数组中的两数之和(Sum of Two Numbers in a Sorted Array)——双指针|面试辅助|数组面经

66次阅读
没有评论

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).


这是经典的 有序数组两数之和 。用 双指针 i 从左、j 从右;若 arr[i]+arr[j] < T 则左指针右移,否则右指针左移,等于就返回。 时间 O(n)空间 O(1)
关键词:双指针、数组、算法面试题、面试辅助、面经、两数之和。

VOprep 团队长期陪同学员实战各类大厂 OA 与 VO,包括 Apple、Google、Amazon、Citadel、SIG 等,提供实时答案助攻、远程陪练与面试节奏提醒,帮助大家在关键时刻不卡壳。
如果你也在准备 Tiktok 或类似工程向公司,可以了解一下我们的定制助攻方案——从编程面到系统设计,全程护航上岸。

正文完
 0