Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Two Sum in Sorted Array

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Two Sum in Sorted Array. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given a sorted array of integers numbers and an integer target, return the 0-based indices of the two elements whose sum is exactly target. Exactly one valid pair exists, and you may not use the same element twice. Solve it using a two-pointer approach.

Constraints

  • 2 <= len(numbers) <= 10^5
  • -10^9 <= numbers[i] <= 10^9
  • numbers is sorted in non-decreasing order
  • Exactly one valid answer exists

Function Signature

def two_sum_sorted(numbers, target):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output