Is it necessary to make arraylist in this?

Can’t we do this by directly printing?
How can I print the elements in sorted order without making arraylist

@bhavik911,

  1. No, we can’t solve this directly by printing because we have to preserve the order of elements.
  2. We cannot print because the characters are in a random order and we have to preserve the order of characters as well