FastPrepTwo Sum
Problems/Two Sum

Two Sum

London Stock Exchange logoLondon Stock Exchange● EasyNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names Two Sum but gives no statement or examples. Here, we use the usual rule of one unique pair, with zero-based indices, and we added limits. Our version is about 80% the same as the reported question.

Given nums and target, return the two distinct indices whose values add to target.

Exactly one valid pair exists. Return [i, j] with zero-based indices and i < j. The array is not necessarily sorted, and an element cannot be used twice.

Function

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

Examples

Example 1

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

The values at indices 0 and 1 are 2 and 7. Their sum is 9.

Example 2

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

The values at indices 1 and 2 sum to 6. The single value 3 cannot be reused.

Example 3

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

The equal values occupy different indices, so indices 0 and 1 form a valid pair.

Constraints

  • 2 <= nums.length <= 100000.
  • Every value in nums is between -1000000 and 1000000, inclusive.
  • The target is between -2000000 and 2000000, inclusive.
  • Exactly one pair of distinct indices has values summing to target.

More London Stock Exchange interview questions

  • Implement a Queue Using an ArrayPHONE SCREEN · Seen Feb 2020
  • Lowest Common Ancestor in a Binary TreePHONE SCREEN · Seen Feb 2020
  • Palindrome PartitioningPHONE SCREEN · Seen Feb 2020
  • Two Sum in a Sorted ArrayPHONE SCREEN · Seen Feb 2020
  • Group Anagram StringsONSITE INTERVIEW · Seen Apr 2020
  • Implement Key Equality and HashingONSITE INTERVIEW · Seen Apr 2020

Similar questions at other companies

  • Majority ElementByteDance · PHONE SCREENByteDance interview questions
  • Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
  • Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Find Unique ElementsCisco · PHONE SCREENCisco interview questions
  • Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Two SumAmazon · OA · PHONE SCREEN
  • Employee Count Median, Mean and ModeClay · PHONE SCREEN
  • Two SumBNSF Railway · PHONE SCREENBNSF Railway interview questions
  • Single-Condition Product FilterCrowdstrike · PHONE SCREENCrowdstrike interview questions
  • Cross-Day User Trust ScoresAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
All London Stock Exchange interview questionsSee London Stock Exchange hiring insights
Saved
class Solution {
    public int[] twoSum(int[] nums, int target) {
        // Write your solution here.
    }

}
Checking account…