Added logN checking for existing answer instead of linear.