Python interview question: two sum in a sorted array

EasyTwo pointers

Problem

prices is a category’s price list, sorted ascending, and at most one pair of different items adds up to exactly target. Return that pair’s indices [i, j] with i < j, or [-1, -1] if there’s none. Use O(1) extra memory, without a price dictionary.

def pair_in_sorted(prices: list[int], target: int) -> list[int]:

Example

Solve it free

Checked against hidden tests, right in your browser. No sign-up needed.

Skills it tests

More interview questions

All questions