This is eye opening for me. Really struggled to figure out the method for converting value to [value] and now it seems obvious. I tried a similar approach, but ended up doing too much by not understanding some fundamentals. I like your solution best!

Your solution is actually an O(n^2) solution, due to the calls of firstIndex and lastIndex for each character. My solution is O(n) as it uses only constant time operations for each character. That doesn't really matter for smal examples like this, but for longer strings for larger alphabets, it will make a difference.

That default is hot.

I can't believe i missed that. Well done !

This is eye opening for me. Really struggled to figure out the method for converting value to [value] and now it seems obvious. I tried a similar approach, but ended up doing too much by not understanding some fundamentals. I like your solution best!

Constants get elimitated in big-O notation O(3*n) is equivalent to O(n).

I believe your solution is O(n*3)

//first pass

for letter in word { .. }

//second pass

word.map {...}

//third pass

.joined()

Oh, why didn't I guess this way... )

Why couldn't I think of this solution?

Your solution is actually an O(n^2) solution, due to the calls of firstIndex and lastIndex for each character. My solution is O(n) as it uses only constant time operations for each character. That doesn't really matter for smal examples like this, but for longer strings for larger alphabets, it will make a difference.

Comparing with my solution this one is as fast as mine but is less readable.

Sample tests use wrong function

## Loading more items...