Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/daily-coding-challenges-python/681cb1b0dab50c87ddb2e518.md
T
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.5 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
681cb1b0dab50c87ddb2e518 Challenge 7: Targeted Sum 29 challenge-7

--description--

Given an array of numbers and an integer target, find two unique numbers in the array that add up to the target value. Return an array with the indices of those two numbers, or "Target not found" if no two numbers sum up to the target.

  • The returned array should have the indices in ascending order.

--hints--

find_target([2, 7, 11, 15], 9) should return [0, 1].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_target([2, 7, 11, 15], 9), [0, 1])`)
}})

find_target([3, 2, 4, 5], 6) should return [1, 2].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_target([3, 2, 4, 5], 6), [1, 2])`)
}})

find_target([1, 3, 5, 6, 7, 8], 15) should return [4, 5].

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_target([1, 3, 5, 6, 7, 8], 15), [4, 5])`)
}})

find_target([1, 3, 5, 7], 14) should return 'Target not found'.


({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(find_target([1, 3, 5, 7], 14), "Target not found")`)
}})

--seed--

--seed-contents--

def find_target(arr, target):

    return arr

--solutions--

def find_target(arr, target):
    for i in range(len(arr)):
        for j in range(i + 1, len(arr)):
            if arr[i] + arr[j] == target:
                return [i, j]
    return 'Target not found'