Ctrl K
Problem

Pair in a Sorted List

Medium · Pair in a Sorted List

A shop's price list `prices` is already sorted in non-decreasing order. Pick two different items that together cost exactly `budget`. Return their positions `[i, j]`, counting **from one**, with `i < j`. Exactly one such pair is guaranteed. The same item cannot be used twice, though two different items may have the same price. Try to use only O(1) extra memory; the fact that the list is sorted is the main hint.…

Solve the problem →