FastPrepTwo Sum
Problems/Two Sum

Two Sum

IBM logoIBM● EasyINTERNPHONE SCREEN

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A candidate reported Two Sum in an IBM software engineering internship interview. The full prompt was not shared. This practice version supplies the index convention, unique-pair guarantee, examples, and bounds. Approximate source match: 85%.

Given an integer array nums and an integer target, return the indices of the two numbers whose sum equals target.

  • Use two different indices. Equal values at different indices are allowed.
  • Exactly one unordered pair of indices is valid.
  • Return the two zero-based indices in increasing order.

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 are 2 and 4. Their sum is 6.

Example 3

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

The two values are equal, but they occupy different indices. Their sum is 6.

Constraints

  • 2 <= nums.length <= 10^4
  • -10^9 <= nums[i], target <= 10^9
  • Exactly one pair of different indices has a sum equal to target.

More IBM interview questions

  • Alternate Odd and Even Numbers with Two GoroutinesPHONE SCREEN · Seen Nov 2026
  • Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Nov 2026
  • Longest Palindromic SubstringPHONE SCREEN · Seen Oct 2026
  • Merge Two Sorted ListsPHONE SCREEN · Seen Oct 2026
  • Reverse a Linked ListPHONE SCREEN · Seen Oct 2026
  • Variadic Function Library MatchesPHONE SCREEN · Seen Sep 2026
  • Count Active Employee Access GrantsPHONE SCREEN · Seen Sep 2026
  • Count Triplets Within a Value RangePHONE SCREEN · Seen Sep 2026
  • Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
  • Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026

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

Interview reports that mention this question

  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences

IBM interview experiences

  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public int[] twoSum(int[] nums, int target) {
        // write your code here
    }
}
Checking account…