Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
IIFE & NFE & recursion
According to the description "The key has to be shortest of all possible keys that can be used to code the message: i.e. when the possible keys are 12 , 1212, 121212, your solution should return 12.". 19391 and 1939 may be used as a key. 1939 is shorter. I hope it helps.
That kata is a third one in a series. Start from the first one and it will be clear.
I see you meant in the tags, then yes.
This is
O(n)
for the initial count (first line map/reduce) and thenO(n)
again for the summarisation, for a total complexity ofO(n)
wheren
is the total length of the input.It's not really any faster than most of the solutions to this problem, however (including yours). At this level it's far less about the Big O complexity of the algorithm and far more about the constant factors and language/algo-specific performance characteristics.
Your solution has a bug and passes unexpected values into some of predicates. It's not a kata issue.