solution for linked list