Find two smallest elements in an unsorted array using only one pass i.e. O(n)
Anonymous
Initialize two variables which will the first and second elements in the array respectively. As you loop, if current value is less than both then update both, if it's between the two then only update second.
Check out your Company Bowl for anonymous work chats.