The Captain's Room

  • + 0 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 :

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    K = int(input())
    
    # We took 2 lists : one with duplicate, one without duplicate
    room_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 duplicate
    for element in room_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])