Replace LinkedList with ArrayDeque as ArrayDeque is faster