It's concise and cool but isn't the time complexity O(n^2)? you can do it with O(n) complexity by doing a first pass over the string to record counts of each character in an array (can explit the convertability of ASCII characters to integers) although there is a tradeoff in space complexity and verbosity...
I usually avoid recursive algorithms when easy iterative solutions exist because of the savings in space from the buffered function calls... not to mention the overhead for all the new LinkedLists that are instantiated. Looks cool though.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
It's concise and cool but isn't the time complexity O(n^2)? you can do it with O(n) complexity by doing a first pass over the string to record counts of each character in an array (can explit the convertability of ASCII characters to integers) although there is a tradeoff in space complexity and verbosity...
I usually avoid recursive algorithms when easy iterative solutions exist because of the savings in space from the buffered function calls... not to mention the overhead for all the new LinkedLists that are instantiated. Looks cool though.