Point72 interview question

Easy hackerrank question made harder by requiring linear time complexity