Now in Beta

    Practice Your AI Coding Skills

    Hard-AI Challenges to sharpen how you work with AI.

    …and more is coming

    Try a Challenge

    ChallengeFrame Tasks for AI

    two-sum

    Given an array of integers nums and an integer target, find two numbers such that they add up to target and print their 0-indexed indices.

    You may assume that each input would have exactly one solution, and you may not use the same element twice.

    Input format

    The first line contains N, the length of the array.

    The second line contains N space-separated integers.

    The third line contains the target integer.

    Output format

    Print two space-separated 0-indexed indices of the numbers that add up to the target.

    Sample input

    4
    2 7 11 15
    9

    Sample output

    0 1

    Explanation: Because nums[0] + nums[1] = 2 + 7 = 9, we output 0 1.

    Sample input

    3
    3 2 4
    6

    Sample output

    1 2

    Sample input

    2
    3 3
    6

    Sample output

    0 1
    solution.py
    Time Limit: 4sStorage Limit: 256MB
    1# AI-generated code will appear here
    2# The program reads from stdin and writes to stdout.

    Cookie preferences

    We use cookies to understand how visitors use our site. You choose what to allow. Privacy Policy