powers. The opponent has already lined up in the order powers, so position i holds a fighter of strength powers[i].
You may line up your fighters (the same multiset of strengths) in any order. You win position i if your fighter there is strictly stronger than theirs.
Return the largest number of wins you can get.powers=[4, 1, 4, 2, 7] → 3
Against [4, 1, 4, 2, 7] we field [7, 2, 1, 4, 4]: 7 > 4, 2 > 1 and 4 > 2 win, three in total. You cannot do better: only our single 7 can beat either of their 4s, and nobody beats their 7.
powers=[3, 3, 3] → 0
All fighters are equally strong and a tie is not a win, so the answer is 0.
powers=[5, 10, 15, 20] → 3
len(powers) ≤ 10⁵powers[i] ≤ 10⁹powers=[4, 1, 4, 2, 7]
3
Run checks the first 3 tests in your browser. Submit checks all 88 tests on the server, hidden ones included.