Add O(n) solution using linked list