LeetCode Problems Flashcards
1
Q
Given an unsorted array of numbers, what is an O(n) method of finding the indices of the two numbers that add up to equal a provided target number?
A
Use a hashmap to store each number against its index as you look at them. As you iterate through the array, check the hashmap to see if the target minus the current number exists within the hashmap (HashMap.containsKey() is of O(1) complexity)