FastPrepTwo Sum
Problems/Two Sum

Two Sum

Capital One logoCapital One● EasyFULLTIMEOAONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2022 Capital One report from an associate software engineer candidate lists two sum among its coding questions. A 2021 final-round report does not name the task, but its question looks like the same one. The answer was a pair of positions in an array, and a follow-up switched the answer to the two numbers themselves.

The reports give no input format, no rule for several valid pairs, and no limits. In this version the input always holds a single fitting pair. The answer is [i, j] with the smaller position first, counting from 0. Returning the values instead is covered as a follow-up in the editorial, and tests do not check it. The limits are our choices.

Our version is about 85% the same as the reported questions.

Find the two positions in nums whose values add up to target. There is always exactly one such pair of positions i < j. The two positions must be different, but their values may be equal.

Return the pair as [i, j], smaller index first. Indexes start at 0.

Function

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

Examples

Example 1

nums = [31,-12,7,44,-5,19]target = 39return = [3,4]

44 + (-5) = 39, and 44 and -5 are at indexes 3 and 4. Every other pair gives a different total, for example 31 + 7 = 38 and 7 + 19 = 26.

Example 2

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

Slots 2 and 3 each hold a 6, and 6 + 6 = 12. They are separate slots of the array, so taking both is fine, even though the values match.

Example 3

nums = [12,-8,30,4,-25]target = -33return = [1,4]

-8 + (-25) = -33, using indexes 1 and 4. Every pair that includes 12, 30 or 4 adds up to more than -33.

Constraints

  • 2 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • Exactly one pair of indexes i < j has nums[i] + nums[j] == target.

More Capital One Online Assessment questions

  • Branch with the Most FilesOA · Seen Nov 2026
  • Earliest Meeting Time for All EmployeesOA · Seen Nov 2026
  • Earn the Most 🐝OA · Seen Nov 2026
  • Rank Football TeamsOA · Seen Oct 2026
  • Count Subarrays Matching a Comparison PatternOA · Seen Oct 2026
  • Arithmetic Triplets After QueriesOA · Seen Oct 2026
  • Count One-Swap Number PairsOA · Seen Oct 2026
  • Distinct Values on Maximum-Sum FramesOA · Seen Oct 2026
  • Sort Adjacent PairsOA · Seen Oct 2026
  • Bouncing Diagonal WeightsOA · Seen Oct 2026

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
  • 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
  • Filter Pins by Excluded IDsPinterest · ONSITE INTERVIEWPinterest interview questions

Capital One interview experiences

  • Capital One Coding OA Questions: 3 Experiences
  • Capital One Experienced Engineer Power Day and OA: 6 Experiences
  • Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
  • Capital One TDP Agentic Round (AI Coding): 7 Experiences
  • Capital One SWE Power Day, Level Not Reported: 6 Experiences
  • Capital One TIP Intern OA and Power Day: 13 Experiences
All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public int[] twoSum(int[] nums, int target) {
        // Write your code here.
    }
}
Checking account…