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.
woah, so that's what it was
This comment is hidden because it contains spoiler information about the solution
If you don't want to copy the parameter (time and memory constraints), but want to use it without altering it, you pass it by const reference.
if you don't want to change number you shouldn't pass it as a reference
Because he is passing
number
as a reference.This would mean if he would change
number
in the body ofopposite
, the value would be also manipulated outside the function.This is clearly not wanted.
const
declares that number will be treated as constant in this function and has two purposes:number
as a reference, it will not be changedopposite
can not accidently changenumber
as this would result into a compilation error.What's the benefit of making the function take a const int?
I was having the same issue and resolved it by handling the case of one of the test cases being an empty string. Check at the start of your code if strng is empty and if so return an empty string.