</>
ShikshaCSLearn. Code. Grow.
šŸ”
ā˜• Support Us
ShikshaCS›Practice Problems
DSAEasyArraysHashing

Two Sum

šŸ“‹ Problem

Given an array of numbers and a target value, find two numbers in the array that add up to the target, and return their indices.

🧭 Approach

A brute-force check of every pair takes O(n²). Instead, use a hash map: as you go through the array, for each number check if (target - number) already exists in the map. If yes, you found your pair instantly. If not, add the current number to the map and keep going.

← Back to all Problems