Logo
SmartTutorS U L T A N 

Programming & ICPC Coach

World-class programming mentor for competitive programming

Topics

Data Structures

Your Stats

Problems Solved142
Contest Rating1847
Current Streak12 days

Two Sum

EasyArrays

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

Example:

Input: nums = [2,7,11,15], target = 9

Output: [0,1]

Explanation: nums[0] + nums[1] = 2 + 7 = 9

2 ≤ nums.length ≤ 10⁴-10⁹ ≤ nums[i] ≤ 10⁹Only one valid answer exists

AI Coach Suggestion

For Two Sum, consider using a hash map for O(n) time complexity instead of nested loops O(n²). Store each number and its index as you iterate.