linear time solution to search (with duplicates)