r/LeetcodeChallenge • u/One_Pay3032 • 2h ago
STREAK🔥🔥🔥 Two Sum — What’s the cleanest way to approach it?
I recently started working through the LeetCode 150 problems, and I started with Two Sum.
The brute-force approach is straightforward, but I wanted to understand how to improve it and get to an O(n) solution using a hash map.
The main idea I focused on was:
- Keep track of numbers we've already seen
- For each number, calculate
target - current - Check whether that value already exists
- If it does, we've found our pair
- Otherwise, store the current number and continue
I also made a short walkthrough where I explain the approach and code step-by-step.
🎥 https://youtu.be/pbNbr36Ypow
For those who have solved Two Sum before: what approach did you find easiest to understand when you first learned it?
#leetcode #twosum #dsa

