Colored Balls: Revisited (Codeforces 1728A)
Tags: Greedy, sortings

The title is a reference to the very first Educational Round from our writers team, Educational Round 18.There is a bag, containing colored balls. There are $$$n$$$ different colors of balls, numbered from $$$1$$$ to $$$n$$$. There are $$$\mathit{cnt}_i$$$ balls of color $$$i$$$ in the bag. The total amount of balls in the bag is odd (e. g. $$$\mathit{cnt}_1 + \mathit{cnt}_2 + \dots + \mathit{cnt}_n$$$ is odd).In one move, you can choose two balls with different colors and take them out of the bag.At some point, all the remaining balls in the bag will have the same color. That's when you can't make moves anymore.Find any possible color of the remaining balls.

Input: The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases.The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 20$$$) — the number of colors.The second line contains $$$n$$$ integers $$$\mathit{cnt}_1, \mathit{cnt}_2, \dots, \mathit{cnt}_n$$$ ($$$1 \le \mathit{cnt}_i \le 100$$$) — the amount of balls of each color in the bag.The total amount of balls in the bag is odd (e. g. $$$\mathit{cnt}_1 + \mathit{cnt}_2 + \dots + \mathit{cnt}_n$$$ is odd).

Output: For each testcase, print a single integer — any possible color of the remaining balls, after you made some moves and can't make moves anymore.

Note: In the first testcase, your first and only move can be one of the following:   take balls with colors $$$1$$$ and $$$2$$$;  take balls with colors $$$1$$$ and $$$3$$$;  take balls with colors $$$2$$$ and $$$3$$$. After the move, exactly one ball will remain. Its color can be $$$3, 2$$$ or $$$1$$$ depending on the move.In the second testcase, you can't make moves at all — there is only color of balls already. This color is $$$1$$$.In the third testcase, you can keep removing one ball of color $$$1$$$ and one ball of color $$$2$$$ until there are no more balls of color $$$1$$$. At the end, three balls of color $$$2$$$ remain.

Sample Inputs:
3
3
1 1 1
1
9
2
4 7

Sample Outputs:
3
1
2

Solution (Python):
cases = int(input())
for i in range(cases):
    sze = int(input())
    lst = list(map(int, input().split()))
    biggest = 0
    for j in range(sze):
        temp = lst[j]
        if temp > biggest:
            biggest = temp
            ans = j + 1
    print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(100000000)
input = lambda : sys.stdin.readline().strip()
write = lambda x: sys.stdout.write(str(x) + '\n')
t = int(input())
for _ in range(t):
    n = int(input())
    cnt = list(map(int, input().split()))
    print(cnt.index(max(cnt)) + 1)

Solution (Python):
q = int(input())
for _ in range(q):
    n = int(input())
    a = list(map(int, input().split()))
    print(a.index(max(a)) + 1)