Saturday, January 31, 2026
Two Sum
Akash AmanUpdated: February 2026
Two Sum
easy
💡 Intuition
- As we scan the array, we trade extra memory for speed by remembering past numbers, allowing us to instantly check whether the current number completes a valid pair. Eg
target − currentNumbershould exist in past numbers. - We can maintain a hashmap to keep track of past number while iterating.
🚀 Solution
go
⏳ Time Complexity
- Since we are taking single loop for the array of length n, the time complexity will be
O(n)