FastPrepTwo Sum
Problems/Two Sum

Two Sum

Vanguard logoVanguard● EasyFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report names Two Sum and links a standard pair-sum exercise, but does not give its OA examples or limits. Our version needs one unique pair of different indices, in increasing index order. It is about 95% the same as the named exercise.

Given an integer array nums and an integer target, return two different indices whose values add up to target.

For this exercise, assume exactly one unordered pair of distinct indices satisfies the target. Return the smaller index first. The array is not necessarily sorted, and you cannot use one element twice.

Function

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

Examples

Example 1

nums = [4,1,7,6]target = 10return = [0,3]

The values at indices 0 and 3 are 4 and 6, which sum to 10.

Example 2

nums = [5,5]target = 10return = [0,1]

Equal values can form the answer when they occupy two different indices.

Example 3

nums = [-3,4,9,-1]target = 8return = [2,3]

The values 9 and -1 sum to 8; return their original indices.

Constraints

  • For this exercise, assume 2 <= nums.length <= 10^5.
  • For this exercise, assume -10^9 <= nums[i], target <= 10^9.

More Vanguard Online Assessment questions

  • Valid ParenthesesOA · Seen Sep 2026
  • Are They PangramsOA · Seen Nov 2025
  • Missing WordsOA · Seen Nov 2025
  • Spam DetectionOA · Seen Nov 2025
  • Binge WatchingOA · Seen Jan 2023
  • Minimum Moves Around a Circular ArrayOA · Seen Aug 2022
  • Maximum Occurring CharacterOA · Seen Mar 2022
  • Picking TicketsOA · Seen Mar 2022
  • Tool List: Two Smallest ValuesOA · Seen Nov 2021
  • Group AnagramsOA · Seen Nov 2019

Similar questions at other companies

  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Count Valid Square PairsAuxoAI · OA
  • Two SumAmazon · OA · PHONE SCREEN
  • Find Words That Can Be Formed by CharactersTabaPay · OA
  • Basic Item DiscountsPalantir · OAPalantir interview questions
  • Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
  • Customer Signer ScreeningState Farm · OA
  • Minimum Magic Stones After MergesElevenLabs · OAElevenLabs interview questions
  • K Most Recent Unique Request IDsMicrosoft · OAMicrosoft interview questions
  • Distinct Products After Removing One ElementHSBC · OAHSBC interview questions

Interview reports that mention this question

  • Vanguard Tech and Risk Older OAs: 12 Experiences (Part 3 of 3)
  • Vanguard Software Older Rounds: 13 Experiences (Part 2 of 3)
  • Vanguard Tech Intern Interviews: 37 Experiences (Part 1 of 3)
All Vanguard interview questionsSee Vanguard hiring insights
Saved
class Solution {
    public int[] twoSum(int[] nums, int target) {
        // Write your code here.
    }
}
Checking account…