Your question is Two Sum Without Nested Loops. 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.
An Ancestry Marketing campaign assigns an integer score to each audience segment. Given a list of scores and a target total, find the indices of two distinct segments whose scores add up to the target.
Design an algorithm that avoids two nested loops and runs in linear time on average. Return the indices in ascending order. Each input is guaranteed to contain exactly one valid pair.
Implement two_sum(nums, target):
nums, a list of integers, and target, an integer.target.def two_sum(nums, target):