We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Except few boundary condition your soultion working for the rest. The soultion will leads to infinte loop and thus result in runtime exception if min == max;
Sample case summary as per the above code.
stones = 5 - 1 = 4
one = 1
two = 1
min = 4
max = 4
current = 4
difference = 4 - 4 = 0
Now if you will do a dry run over your while loop, its easy to find that it will lead to infine loop.
It can be fixed easliy.
Thanks,
Varun
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Manasa and Stones
You are viewing a single comment's thread. Return to all comments →
Except few boundary condition your soultion working for the rest. The soultion will leads to infinte loop and thus result in runtime exception if min == max; Sample case summary as per the above code. stones = 5 - 1 = 4 one = 1 two = 1 min = 4 max = 4 current = 4 difference = 4 - 4 = 0
Now if you will do a dry run over your while loop, its easy to find that it will lead to infine loop.
It can be fixed easliy.
Thanks, Varun