3 ms·
I find it amusing that the author asks for an optimal solution that avoids taking up extra space. Then in his example solution he makes two copies of the origin
by justinhj 10y ago
I find it amusing that the author asks for an optimal solution that avoids taking up extra space. Then in his example solution he makes two copies of the original string to convert it to lowercase and strip invalid characters.
Using a regex is overkill for the simple rejection of invalid characters. The job could be done in a single loop with worse case runtime n/2. Sure his solution is still linear time but he did ask for optimal.
It just goes to show that you can't win the interview game because everyone looks for different things. There is definitely good advice in this article though.