implemented kthToLast algorithm