You are at a fine art auction and are looking for a specific painting. There are N people who have gathered to place a bid on that same painting.
The rules of at this auction are a bit different, Such that, the person with the lowest unique bid wins the auction.
People are numbered from 1 to N. You are given an array bids which depicts the bidding price of the i-th person. Your task is to find the position of the person who will win the auction. If there is no winner, return -1.
Input Format:
The first line contains an integer N, denoting the number of participants.
Each line i of the N subsequent lines (where 0 <= i < N) contains an integer describing bid price of the i-th participant.
Constraints:
1 <= N <= 10 ^ 5 1 <= bids[i] <= 10 ^ 5
Sample Input 1 :
2 1 1
Sample Output :
-1
Explanation :
There are 2 people at auction. Both have placed a bid of same amount hence nobody wins.
Sample Input 2:
3 2 1 3
Sample Output :
2
Explanation:
The lowest unique bid is of person 2.
Sample Input 3:
4 2 2 2 3
Sample Output:
4
Explanation:
The lowest bid is of person 1,2,3 but lowest unique bid is of person 4.
Let's see the implementation:
N = int(input()) bids = [] temp = N while N != 0 : bid = int(input()) bids.append(bid) N -= 1 d = dict.fromkeys(bids) for key in d : d[key] = [] for i in range(temp) : d[bids[i]].append(i) s = list(sorted(d.items())) flag = 0 for item in s : if len(item[1]) == 1 : print(item[1][0] + 1) flag = 1 break if flag : pass else : print(-1)