text function twoSum(nums, target): map = empty hash map for i from 0 to length(nums) - 1: complement = target - nums[i] if complement in map: return [map[complement], i] map[nums[i]] = i return [] // no solution found Time complexity: . You traverse the array once. Space complexity: . In the worst case, you store all elements in the map.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/arrays-hashing/two-sum-pseudocode
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████████████████████████████████████████████████████████████████████████████████