SerialReads

Find Two Numbers with a Given Sum

Given an unsorted array of integers and a target value, find any pair that adds up to the target.
Return the two indices or report that no such pair exists.

Need a hint?
  • Sort the array first.
  • Use one pointer at each end and move inward based on the sum.

algorithms two-pointer