Two Sum

๐ง Problem
Two Sum
๐ท๏ธ Tags
array, hash table
๐ Difficulty
Easy
โ
Success Rate: 48.5%
๐ฅ Submissions: 13,207,990
๐ Accepted: 6,403,821
โค๏ธ Reactions
๐ Likes: 31242
๐ Dislikes: 988
๐ก Hints
A really brute force way would be to search for all possible pairs of numbers but that would be too slow. Again, it's best to try out brute force solutions for just for completeness. It is from these brute force solutions that you can come up with optimizations. So, if we fix one of the numbers, say x, we have to scan the entire array to find the next number y which is value - x where value is the input parameter. Can we change our array somehow so that this search becomes faster? The second train of thought is, without changing the array, can we use additional space somehow? Like maybe a hash map to speed up the search?
๐ Similar Questions
- 3Sum
- 4Sum
- Two Sum II - Input Array Is Sorted
- Two Sum III - Data structure design
- Subarray Sum Equals K
- Two Sum IV - Input is a BST
- Two Sum Less Than K
- Max Number of K-Sum Pairs
- Count Good Meals
- Count Number of Pairs With Absolute Difference K
- Number of Pairs of Strings With Concatenation Equal to Target
- Find All K-Distant Indices in an Array
Leetcode Link : Two Sum
Subscribe to my newsletter
Read articles from RedAurther directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
