Two Sum (Hash Drill)
Read the lesson → understand the pattern → then code. Tutor works offline (built-in teacher); optional Cursor/Gemini keys upgrade chat quality.
Topic refresher: Hashing — Pay Space, Buy Time
Replace nested loops with unordered_map / unordered_set lookups.
unordered_map<int,int> mp;
for (int i = 0; i < n; i++) {
int need = target - nums[i];
if (mp.count(need)) return {mp[need], i};
mp[nums[i]] = i;
}EasyHashingLeetCode #1
Same Two Sum — force the hash solution
No nested loops. Prove you own unordered_map.
Examples
Example 1
Input
4 9 2 7 11 15
Output
0 1
Example 2
Input
3 6 3 2 4
Output
1 2
Stuck? Take a nudge
C++17Autosaves