https://alkeshghorpade.me/post/geeks-for-geeks-pair-in-array-with-sum-equal-to-target
For further actions, you may consider blocking this person and/or reporting abuse
For further actions, you may consider blocking this person and/or reporting abuse
moseeh -
Neel Patel -
Dário Prazeres -
Labby -
Top comments (2)
Hi, nice solution you pointed out. I solved a similar problem back at AdventOfCode. I leveraged a HashMap to solve this problem in a time complexity of O(n), but slightly increased space complexity (given the array is already present and not to be computed or serialized from storage).
Given the following input:
Loop through the map and check if
target - currentItem
(since lookup is possible in constant time) exists also in the map -> sum foundLooping through whole map (worst case) sums up to a time complexity of O(n) as stated above.
Hey thanks for the above solution. I have posted about this approach in my first blog
alkeshghorpade.me/post/leetcode-tw...