FastPrepTwo Sum
Problems/Two Sum

Two Sum

Shnoor International logoShnoor International● EasyINTERNONSITE INTERVIEW

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Shnoor International on-campus intern interview, in a round that mixed technical and HR questions. The report names this problem only as Two Sum, and says the friend of the poster was asked to make the solution faster.

The report gives no statement, examples, limits or output rules. Here we use the usual task with that name: given an array and a target, return the indices of the two numbers that add up to the target. Exactly one pair works, you return its two indices in increasing order, and the limits are the usual ones for this task. The editorial goes from checking every pair to a hash map.

Our version is about 90% the same as the reported question.

Given an integer array nums and an integer target, return the indices of the two numbers that add up to target.

Exactly one pair of indices works. You may not use the same element twice, but two different elements may hold the same value. Indices start at 0. Return the two indices in increasing order.

Function

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

Examples

Example 1

nums = [3,8,12,5]target = 8return = [0,3]

nums[0] + nums[3] = 3 + 5 = 8. No other pair adds up to 8; the 8 at index 1 would need a 0.

Example 2

nums = [5,2,8]target = 10return = [1,2]

nums[1] + nums[2] = 2 + 8 = 10. The 5 would need another 5, and it cannot be paired with itself.

Example 3

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

The two 4s are different elements, so nums[0] + nums[3] = 4 + 4 = 8 is allowed.

Constraints

  • 2 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9
  • -10^9 <= target <= 10^9
  • Exactly one valid answer exists.

More Shnoor International Onsite Interview questions

  • Merge Overlapping IntervalsONSITE INTERVIEW · Seen Nov 2026
  • String CompressionONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Best Average Student ScoreGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • 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
  • Two SumOptimus Information · ONSITE INTERVIEWOptimus Information interview questions
  • Keep the First Key for Each Distinct ValueOneTrust · ONSITE INTERVIEW
See Shnoor International hiring insights
Saved
class Solution {
    public int[] twoSum(int[] nums, int target) {
      // Write your code here.
    }

}
Checking account…