Interview Query

Target Indices

Have you seen this question before?

Given an array and a target integer, write a function sum_pair_indices that returns the indices of two integers in the array that add up to the target integer. If not found, just return an empty list.

Note: Can you do it on O(n)O(n) time?

Note: Even though there could be many solutions, only one needs to be returned.

Example 1:


array = [1 2 3 4] 
target = 5 


def sum_pair_indices(array, target) -> [0 3] or [1 2]

Example 2:


array = [3]
target = 6 


Do NOT return [0 0] as you can't use an index twice.
Next question: Delivery Estimate Model
Python 3.9.6
Loading editor
Use Shift + Enter to run code