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.
Sorry, I thought this was the solution page so we could just post solutions freely, will use next time
Please, use spoiler flag next time.
This comment is hidden because it contains spoiler information about the solution
It's not correct. Overflow error (int i). For example - expandedForm(Integer.MAX_VALUE): "727379968 + 488372224 + 194313216 + 589934592 + 100000000 + 40000000 + 7000000 + 400000 + 80000 + 3000 + 600 + 40 + 7"
Change varable "i, rem" to "long" type in the function body.
It returns a wrong result due to integer overflow. In order to handle 10-digit numbers properly
i
would have to become10000000000
. But that value does not fit in anint
variable and becomes1410065408
instead. Many top rated solutions for various katas don't work properly with edge case inputs.Why does it fail? what is the flaw in their logic?
String concatenation is not exactly best practice. Additionally, the solution is not fully valid. The following test fails:
assertEquals("2000000000 + 1", Kata.expandedForm(2000000001))
This comment is hidden because it contains spoiler information about the solution
There is the true philosophy of life in this kata.
Why not just use the else for the first line? Why have two seperate if statements?