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.
Prefer using a ternary operator, it increases readability !
return (sum % n == 0) ? sum / n : -1;
It means that we got two cases for our return value :
if sum % n == 0, so that sum is divisible by n, we can return the result of the integer division of sum by n. Otherwise, we return -1. It's a common syntax, try to get used to it :D
Great solution ! But using a stack is better I guess.
EDIT : You can also use basic mathematical operations so you keep using an integer only. Take a look at my solution, we have the same approach :D
Can you please explain more ?
You can use one variable instead of two. Just accumulate everything in a variable called sum without distinction between left and right.
This comment is hidden because it contains spoiler information about the solution