Need help on the if loop

Hello team,

I cannot understand the solution for challenge 10 in Lists module. Could you please explain the if loop part? Thanks.

Course: Educative: Interactive Courses for Software Developers
Lesson: Educative: Interactive Courses for Software Developers

Hi @Ketki_Savle,

In the second solution, the if statement in the for loop will be true when the i is even. Then the code in the if statement will be executed.

lst[i] += (lst[maxIdx] % maxElem) * maxElem

In this line of code, we simply take the mod of the element located on the maxIdx with maxElem and then, multiply it with the maxElem again, and then store this result on the even index of the array. After that, we decrement the maxIds by 1. And in else, we are doing the same, but we are incrementing the maxIds by 1 for odd indexes.

I hope I have answered your query; please let me know if you still have any confusion.

Thank You :blush: