Ad
  • Custom User Avatar

    This is not the most optimized solution, given the constraints of the problem.
    LinkedList remove funtion will traverse the entire list with each call, which is really not needed. Use of an array of size 26 will ensure constant space complexity (as we are not growing linearly) and constant time reach to each character's count (eliminating need for HashMap or something similar).

    You can refer to my solution for comparison. If I am missing some advantage you gain by using linked list, please do reply. I'd love to know! :)