Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Two Sum Given a list of integers and an integer target, write a function that takes the list and the target and returns a new

Two Sum

Given a list of integers and an integer target, write a function that takes the list and the target and returns a new list of indices of any two numbers in the list such that they add up to target.

You may assume that each input will have exactly one solution, and you are not allowed to use the same element at a given index twice.

You may return the list with indices in any order.

Example 1:

Input: numbers = [1, 2, 5, 4, 10], target = 15

Output: [2, 4]

Explanation: numbers[2] = 5 and numbers[4] = 10, which can be added to the target integer, 15.[4, 2] is also acceptable.

Example 2:

Input: numbers = [1, 1] , target = 2

Output: [0, 1]

Example:

Input: numbers = [1, 2, 3], target = 5

Output: [1, 2]

Explanation: numbers[1] + numbers[2] = 2 + 3 = 5

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions