Learner Level
Implement the findTwoSumIndices method that returns indices of two numbers whose sum equals the target.
The input contains an integer array nums, its length size, and an integer target. Your task is to return the indexes of two different elements whose values add up to the target.
For example, in [2,7,11,15] with target 9, the values 2 and 7 are at indexes 0 and 1, so the answer is [0,1].
Use a hash map to remember values already seen and their indexes.
For each number, calculate the value needed to complete the target. If that needed value already exists in the map, return its stored index along with the current index.
If it does not exist, store the current value and index so it can be used by a later number.
Pseudocode:
function findTwoSumIndices(nums, size, target):
seen = empty map
for i from 0 to size - 1:
needed = target - nums[i]
if needed exists in seen:
return [seen[needed], i]
seen[nums[i]] = i
return []