The Captains Room in python - HackerRank Solution
Problem :
One fine day, a finite number of tourists come to stay at the hotel.
The tourists consist of:
→ A Captain.
→ An unknown group of families consisting of K members per group where K ≠ 1.
The Captain was given a separate room, and the rest were given one room per group.
Mr. Anant has an unordered list of randomly arranged room entries. The list consists of the room numbers for all of the tourists. The room numbers will appear
K times per group except for the Captain's room.
Mr. Anant needs you to help him find the Captain's room number.
The total number of tourists or the total number of groups of families is not known to you.
You only know the value of K and the room number list.
Input format :
The second line contains the unordered elements of the room number list.
Constraints :
- 1 < K < 1000
Output Format :
Output the Captain's room number.
Sample Input :
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
Sample Output :
8
Explanation :
Hence, 8 is the Captain's room number.
Solution :
# The Captains Room in python - Hacker Rank Solution # Python 3 # Enter your code here. Read input from STDIN. Print output to STDOUT # The Captains Room in python - Hacker Rank Solution START N = int(input()) storage = map(int, input().split()) storage = sorted(storage) for i in range(len(storage)): if(i != len(storage)-1): if(storage[i]!=storage[i-1] and storage[i]!=storage[i+1]): print(storage[i]) break; else: print(storage[i]) # The Captains Room in python - Hacker Rank Solution END
Disclaimer :-
the above hole problem statement is given by hackerrank.com but the solution is generated by the codeworld19 authority if any of the query regarding this post or website fill the following contact form thank you.
from collections import Counter
n=int(input())
x=Counter(list(map(int,input().split())))
for i in x:
if x[i]==1:
print(i)
K=int(input())
rn=tuple(map(int,input().split()))
for i in range(len(rn)):
if rn[i] not in rn[:i]:
c=rn[i]
print(c)
k=int(input())
x=list(map(int,input().split()))
y=list(set(x))
for i in y:
count=0
for j in x:
if i==j:
count=count+1
if count==1 :
print (i)
# alternate soln.
k=int(input())
x=list(map(int,input().split()))
for i in x:
if x.count(i)==1:
print(i)
k=int(input())
q=list(map(int,input().split()))
dic={}
for i in q:
if(i in dic):
dic[i]+=1
else:
dic[i]=1
test=list(dic.values())[0]
for j in dic:
if(dic[j]!=test):
print(j)
break