change to solution without using auxilliary queue