This problems belongs to sets although but for solving this we have to store room numbers
inside the list or related structure cause sets default remove duplicate items we can not use it to store for
after processing counter occurrence this problems follow sets as theoretically.
Problem:https://www.hackerrank.com/challenges/py-the-captains-room/problem?isFullScreen=true
Code:
# Enter your code here. Read input from STDIN. Print output to STDOUT
k = int(input())
room_nos = list(map(int, input().split()))
from collections import Counter
counts = Counter(room_nos)
for room, count in counts.items():
if count == 1:
print(room)
break
Inpt:
5
1 2 3 6 5 4 4 2 5 3 6 1 6 5 3 2 4 1 2 5 1 4 3 6 8 4 3 1 5 6 2 Output:
8Explanation
The list of room numbers contains elements. Since is , there must be groups of families. In the given list, all of the numbers repeat times except for room number .
Hence, is the Captain's room number.
