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.
It's False. There are two
2
s and one3
so the correct array should beb = {4, 4, 9}
, where{2**2, 2**2, 3**2}
. Instructions below;Correction:
String.join
does use theStringBuilder
library, becauseStringJoiner
usesStringBuilder
under the hood. This means thatString.join
,StringJoiner
, andStringBuilder
are all O(n) optimal ways to concatenate strings, whereas the string concatenation operator+
is O(n^2).This comment is hidden because it contains spoiler information about the solution
nCopies just returns a cheap List that contains the repeated element as many times as specified. String::join doesn't even use a StringBuilder, instead it directly builds the char array for the resulting String. It should be hard to optimize further.
In any case, optimizing for speed at the design level would be premature optimization. In production code, I'd expect code that's easy to read and understand even if it's not fully optimized, except when it turns out to drag performance down.