Title of your commentAs per the question i think answer should be : 5 10 2 1 5 10 2 1. But still it is giving wrong answer. Help appreciated


#1

As per the question i think answer should be :
5 10 2 1 5 10 2 1.
But still it is giving wrong answer. Help appreciated


#2

Well, because it is wrong. If you check it more carefully, there’s a catch. try writing itreations one by one on a paper.


#3

No, it is 5 10 2 1 5 1 2 10 since it is A[A.size()-i] for next part.


#4

Correct answer is 5 10 2 1 5 1 2 10


#5

Check the mod operator (x - 0) % x will be 0, not x, this is the trick


#6

just do a dry run and you will get it , for the 1st iteration , it was (4-0)%4 so it would give 0 since 4 is divisible by 4 and gives remainder 0 but then for other iterations 4-i part is less than 4 so remainder is 4-i itself only


#7

U can run the code in an ide and u will get 5 10 2 1 5 1 2 10