Praise be to Allah.
What appears to be the case is that things such as this are not included in the kind of wagers that are haraam, because the one who is going to give the prize in such instances is the one who is successful and wins, not the one who loses and is defeated. This is different from the usual case in wagers that are haraam, in which the one who usually gives the prize is the one who is defeated.
Based on that, the prize given in this case comes from the one who attained the highest grades, who gave it to the rest of her friends. This is more akin to giving a donation or a gift in gratitude for that blessing that she attained in the exam.
We put the question to Shaykh ‘Abdur-Rahmaan al-Barraak (may Allah preserve him), and he replied: If it is done voluntarily, then there is nothing wrong with it, but if it is done under compulsion, then it is not permissible. End quote.
And Allah knows best.