This is O(n) for the initial count (first line map/reduce) and then O(n) again for the summarisation, for a total complexity of O(n) where n 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.
I give you credits for this one.. Its exacly like mine.
This one looks intelligent.
The cleverest for me, because it is the only solution which logic I got of from the first glimpse.
RileyHunter, thank you for the explanation!
I was confused, when I saw that reduce actually repeated four times. But now, I understand why this solution is better than mine!
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.
Can you explain to me, why this works so fast?
What value will Big O take?
I like this solution more than the one I created. It is more general purpose. I forgot that the lastIndexOf existed :D
the best!!
That is the solution I was looking for! Great move.
+1
That's not how you use a
Map
. You might as well have used a{}
.Will you be able to tell what this function does in, lets say, 10 minutes after you wrote it?
This comment is hidden because it contains spoiler information about the solution
This is amazing!
This comment is hidden because it contains spoiler information about the solution
Loading more items...