0

Can anybody explain how this code is working?

I have made a code for this problem. https://www.sololearn.com/learn/4710/?ref=app But I still don't have any idea how it is working correctly. My code: https://code.sololearn.com/cWYA0oQHHgNA/?ref=app

11th Mar 2020, 7:04 AM
Yogesh Gangwal
Yogesh Gangwal - avatar
2 Respostas
+ 2
The idea: If you have the N numbers of people, the first person will kill the second and give the sword to the third and third person will kill the fourth and the sword will be given to the fifth and so on to the last person and thus the N-1 person will kill the last person and the sword remains with him
12th Mar 2020, 6:17 AM
Muhammad Galhoum
Muhammad Galhoum - avatar
0
In that code k is increasing double rate compare to j, so after n/2 iterations h[0] has already reached n th value. I am not understanding how it is taking values after that.
12th Mar 2020, 6:29 AM
Yogesh Gangwal
Yogesh Gangwal - avatar