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 is pass-by-value since the & was removed. So the input parameters are in fact copies. The code is fuly eqivalent to the function taking const& and then making explicit copies.
It is called a fold expression
I removed also the
&
to take a copy of the inputs. So from the callers perspective the signature is effectively the same.Well, your solution has the same time-compelxity (unless
s2
is much smaller thans1
) but much worse chache-locality due to the use ofstd::multiset
which is a node based structure.Well, in the moment I didn't think of it...
I'd say it's not twice as efficient in general, especially if the input string is long. If I move the comparison against 2 into the first loop I have one additional comparison for each
char
in the input. With this implementation I have at most 26 comparisons to check if the count is two or higher.Since this is not a performance challenge this was more readable to me and since it passed I didn't optimize it further.
Edit: The
std::count_if
part could have even been almost branch-free if I replace it bystd::accumulate
and addstatic_cast<std::size_t>(count.second > 1)
to the accumulator.The kata description says: "The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits."
This comment is hidden because it contains spoiler information about the solution
I've got the advice to never move in a return statement from Scott Meyer's 'Effective Modern C++'
It is a local variable since you are copy-constructing it.
It's a premature pessimization to move in a return statement. It prevents named return value optimization (NRVO). If NRVO were note possible the value would be moved either way since it is a so-called expiring lvalue.
So if you write
return str
the returned value will be either moved to its destination if NRVO is not supported or else the move will be elided away.rust translation, please review and approve.
This comment is hidden because it contains spoiler information about the solution
You are not allowed to use functions to solve this kata. The purpose is to train template metaprogramming.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Loading more items...