Two-Sum Problem

Advanced

Help your friendly space alien, Zog, solve a fun math problem with two numbers! Zog loves numbers and wants to find two numbers that add up to a magical target number. Can you help Zog?

To solve this problem, your task is to write a function that receives a list of numbers and a target number. Your mission is to find two distinct numbers in the list that add up to the target number and return their indices as a list.

Examples:

Let's see some examples to understand the challenge better:

find_two_sum([2, 7, 11, 15], 9) # Returns: [0, 1]

Explanation: The numbers at index 0 (which is 2) and index 1 (which is 7) add up to 9.

find_two_sum([1, 2, 3, 4, 5], 9) # Returns: [3, 4]

Explanation: The numbers at index 3 (which is 4) and index 4 (which is 5) add up to 9.

Challenge Details:

  • You need to ensure your solution finds any one valid pair of indices whose elements sum to the target.
  • You may assume that there will always be exactly one solution.

Enjoy coding and make sure to think logically like Zog to solve this space puzzle!

Geek
Inputs

Arg 1:

[2,7,11,15]

Arg 2:

9
Expected Output
[0, 1]
Actual Output
Two-Sum Problem [advanced] | Coding for Kids