Problem: Home » Practice(school) » Winning Strategy

I have been trying to solve the problem and here is my submission:

I couldn’t findout where I went wrong and I could see most of the other accepted answers contains sorting.

I couldn’t figure out the purpose of sorting for this problem statement.

Finally I got it right.

Here is my submission: