practicing code challenge and improve typescript skill [[Leetcode/Resources|Resources]]
-
Classic Brute force: loop through number of array and then loop through again check if first value + second value = target value, return the current index and the compared index. time complexity would be:
$O(n^2)$ -
One Pass: Using hash map or in this case Object in typescript. loop through the array once, calculate the difference with target - current value, if the difference already in the hash table return that hash map value which is the nums index and the current index otherwise put it inside the hash map. time complexity would be:
$O(n)$