FastPrepTwo Sum
Problems/Two Sum

Two Sum

Apple logoApple● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Apple new grad onsite interview. The report links to the Two Sum exercise. Our version is about 95% the same as the reported question. The returned indices are in ascending order so answers can be compared.

Return the two distinct indices in nums whose values sum to target. Exactly one valid pair exists, and the same array position cannot be used twice.

Return the smaller index first.

Function

twoSum(nums: int[], target: int) → int[]

Examples

Example 1

nums = [2,7,11,15]target = 9return = [0,1]

The values at positions 0 and 1 sum to 9.

Example 2

nums = [3,2,4]target = 6return = [1,2]

Use the values 2 and 4.

Example 3

nums = [3,3]target = 6return = [0,1]

Equal values are allowed when they come from different positions.

Constraints

  • 2 <= nums.length <= 10^4.
  • -10^9 <= nums[i], target <= 10^9.
  • Exactly one pair of distinct indices has the required sum.

More Apple Onsite Interview questions

  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • FIFO Mutex Operation TraceONSITE INTERVIEW · Seen Oct 2026
  • Implement Hit CounterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Parse Nested HTML into a TreeONSITE INTERVIEW · Seen Oct 2026
  • Thread-Safe Concurrent Linked ListONSITE INTERVIEW · Seen Sep 2026
  • Palindrome Match PercentageONSITE INTERVIEW · Seen Sep 2026
  • Binary Tree Nodes at Distance KONSITE INTERVIEW · Seen Aug 2026
  • BST to Sorted Circular Doubly Linked ListONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Sparse Vector Dot Product from TuplesMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Best Average Student ScoreGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Two SumShnoor International · ONSITE INTERVIEW
  • Count Distinct Pairs With Sum KeBay · ONSITE INTERVIEWeBay interview questions
  • List the Key and Value of Every Map EntryNewgen Software · ONSITE INTERVIEW
  • Pizza Price CalculatorMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Cross-Day User Trust ScoresAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Filter Pins by Excluded IDsPinterest · ONSITE INTERVIEWPinterest interview questions
  • Longest Dictionary Word from Nine LettersGoogle · ONSITE INTERVIEWGoogle interview questions

Interview reports that mention this question

  • Apple India SWE New Grad Interviews: 5 Experiences

Apple interview experiences

  • Apple SWE Phone Screen: Subarray Products: 1 Experience
  • Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
  • Apple AI Coding and Related Interviews: 17 Experiences
  • Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
  • Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)
All Apple interview questionsSee Apple hiring insights
Saved
class Solution {
    public int[] twoSum(int[] nums, int target) {
        // Write your solution here.
    }

}
Checking account…