values.
Find the longest prefix (leading part) of the array from which you can delete **exactly one** element so that every number left in it occurs the same number of times.
If nothing remains after the deletion, the condition counts as met.
Return the length of that prefix.values=[4, 4, 7, 7, 9, 9, 9, 2] → 7
The prefix of length 7, [4, 4, 7, 7, 9, 9, 9]: remove one 9 and every number occurs twice. The whole array cannot be fixed with one removal.
values=[5, 5, 5, 1, 1, 1, 8] → 7
Remove the 8 and both 5 and 1 occur three times each, so the whole array works: 7.
values=[3, 3] → 2
values=[4, 4, 7, 7, 9, 9, 9, 2]
7
Run checks the first 3 tests in your browser. Submit checks all 107 tests on the server, hidden ones included.