Skip to main content
All Questions

Given an array, find the two sum.

Easy

Given an array of integers nums and an integer target, write a function twoSum that returns the indices of the two numbers such that they add up to the target. You may assume that each input will have exactly one solution, and you may not use the same element twice. If no such pair exists, return an empty array. If there are multiple pairs of indices that sum to the target, return the indices of the pair where the numbers appear first in the array.

Examples

Input: nums = [2, 7, 11, 15], target = 9 Output: [0, 1] Input: nums = [3, 2, 4], target = 6 Output: [1, 2]

Interview experiences

6 shared
Meta · 2 months ago
"I started with this intro call that was basically 10 rapid-fire technical trivia questions, and they wanted instant answers on the spot. After that, the process moved into the actual interviews. The Python round felt pretty easy because it was just short coding problems one after another, and once I finished one, they immediately pushed the next. The SQL round was the part that really stood out because it happened in an IDE with sample tables and an exact expected output. There was also a 45-minute behavioral in the mix before they made the decision."
Data Engineer · Intern
JP Morgan Chase · 3 months ago
"OA was relatively easy, phone screen was similar, lots of behavioral questions. Overall it was a good process, not very difficult but they do value technical coding skill."
Software Engineer · Intern
Amazon · 2 years ago
"Interviewer were all really nice. Technical portion requires to be thorough in explaining thought process"
Data Engineer · Intern
DocuSign · 2 years ago
"Overall super well. First OA (LeetCode medium DP problem). Then recruiter called me. Then HM called me. Then 2 coding interviews (LeetCode Easy.)"
Software Engineer · Intern
Meta · 3 years ago
"It was very rigorous and I feel like they really emphasize on writing bug free code. I feel like I failed by sounding like too much of a start up person during my behaviorals and they were afraid of me leaving."
Software Engineer · Entry Level / L3
Amazon · 3 years ago
"My interview process started with a coding round focused on data structures and problem-solving, where I was able to understand the problem and write a working approach but struggled with optimizing the solution under time pressure. What went well was my ability to implement a correct baseline solution and explain my thought process, but I didn’t perform as well on edge cases and optimal complexity, which likely impacted the final outcome."
Software Engineer · Senior / L5

Related courses

Course

Machine Learning Engineer Interview Prep

Land your dream machine learning role at Meta, Google, Amazon, Apple, Microsoft, Nvidia, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates. Explore ML system design, core concepts, coding, behavioral interviews, and more.

Course

Data Science Interview Prep

Land your dream data science role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates. Practice statistics, experimentation, coding, SQL, machine learning, behavioral interviews, and more.