Coding

Two Sum

You're presented with an array of integers and a specific target value. Your task is to identify and return the indices of two numbers from the array that add up to the target. You can assume there's exactly one solution, and you can't use the same element twice. The indices can be returned in any order.

Input: nums = [14,8,22,6], target = 20

Output: [1,3]

Explanation: The integers at indices 1 and 3 (8 and 6) sum up to 20, so we return [1, 3].

Software EngineerEngineering ManagerMachine Learning EngineerProduction Engineer

Amazon

Apple

Meta

Reddit

Square

Uber

Did you come across this question in an interview?

Try Our AI Interviewer

Prepare for success with realistic, role-specific interview simulations.

Try AI Interview Now

Interview question asked to Engineering Managers, Machine Learning Engineers, Site Reliability Engineers and other roles interviewing at Outbrain, eToro, Wish and others: Two Sum.