Atlassian OA Interview Question: Find Subrange in a List of Numbers That Add Up to Target

10 Views
No Comments

Find subrange in a list of numbers that add up to target.

The key idea is to find a contiguous subrange whose sum equals the target, ideally in linear time. A common approach is to use prefix sums with a hash map: as you scan the array, store the running sum, and check whether <code>current_sum – target</code> has appeared before. If it has, the elements after that earlier position up to the current index form a valid subrange. This works well even when the list contains negative numbers and zeros.

END
 0