In this exercise, it might happen that some strings cannot be built with different adjacent characters.
In this case, the algorithm returns an empty string, by checking whether the variable previous
is not null and the priority queue is empty.
But this condition appears inside the while
loop, which has !queue.isEmpty()
as a guard condition, so it’ll never reach the if-block to have that final check when we want to.
I think this check could be moved outside the while loop.