PROBLEM 35: Spy Detected!
Problem Reference: Codeforces
You are given an array consisting of () positive integers. It is known that in this array, all the numbers except one are the same (for example, in the array all numbers except one are equal to ).
Print the index of the element that does not equal others. The numbers in the array are numbered from one.
The first line contains a single integer (). Then test cases follow.
The first line of each test case contains a single integer () — the length of the array .
The second line of each test case contains integers ().
It is guaranteed that all the numbers except one in the array are the same.
For each test case, output a single integer — the index of the element that is not equal to others.
Solution:
- t = int(input())
- i = 0
- while i < t:
- n = int(input())
- a = [int(a) for a in input().split()]
- j = 1
- while j <= len(a):
- if a[j] == a[j-1]:
- j = j + 1
- else:
- break
- if j == 1 and a[j] == a[j+1]:
- print(j)
- else:
- print(j+1)
- i = i + 1
No comments:
Post a Comment