We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Hey, I hope it will help. My code pass all test cases, and I think it's not hard to understand the logic behind :
# Enter your code here. Read input from STDIN. Print output to STDOUTK=int(input())# We took 2 lists : one with duplicate, one without duplicateroom_number_list=list(map(int,input().split()))room_number_set=list(set(room_number_list))# Using the list without duplicate, we can delete each room once in the list with duplicate# The logic is that because the Captain room is present only once, it will be the only room to be completely removed from the list with duplicateforelementinroom_number_set:room_number_list.remove(element)# Thanks to that, we have now 2 lists : one with all rooms except the Captain one, and one list with all rooms.# So we can now just use the difference method to get the room of the Captain.room_number_list=set(room_number_list)room_number_set=set(room_number_set)captain_room=room_number_set.difference(room_number_list)print(list(captain_room)[0])
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Captain's Room
You are viewing a single comment's thread. Return to all comments →
Hey, I hope it will help. My code pass all test cases, and I think it's not hard to understand the logic behind :