FastPrepTwo Sum in a Sorted Array
Problems/Two Sum in a Sorted Array

Two Sum in a Sorted Array

London Stock Exchange logoLondon Stock Exchange● EasyNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names Two Sum on a sorted array but not the full rules. Here, positions start at one, there is one valid pair, and you use constant extra space. Our version is about 80% the same as the reported question.

Given an integer array nums sorted in nondecreasing order and a target, find the two distinct positions whose values sum to target.

Exactly one valid pair exists. Return [i, j] using one-based positions with i < j. Use constant extra space, apart from the returned pair.

Function

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

Examples

Example 1

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

The first and second values are 2 and 7, so the one-based answer is [1,2].

Example 2

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

The second and fourth values are -1 and 3. Their sum is 2.

Example 3

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

The two positions are different even though their values are equal.

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.
  • The values are in nondecreasing order.

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 SumPHONE 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

  • Compact Conversation History by Token BudgetSierra · PHONE SCREENSierra interview questions
  • Remove Duplicates from Sorted ArrayNykaa · PHONE SCREENNykaa interview questions
  • Minimum Index Distance Between Person and CakeSnowflake · OA · PHONE SCREENSnowflake interview questions
  • Squares of a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
  • Closest Vehicle and Charger in a LineSpotify · PHONE SCREEN
  • Correct an In-Place Array ReversalDuolingo · PHONE SCREENDuolingo interview questions
  • Remove Duplicates From Sorted Array In PlaceKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Merge Two Sorted ArraysCapgemini · PHONE SCREENCapgemini interview questions
  • Maximize Distance to the Closest Occupied SeatAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Remove Duplicates From Sorted Array In PlaceGet My Parking · PHONE SCREEN
All London Stock Exchange interview questionsSee London Stock Exchange hiring insights
Saved
class Solution {
    public int[] twoSumSorted(int[] nums, int target) {
        // Write your solution here.
    }

}
Checking account…