Started on O(n) solution