The Captain's Room

Sort by

recency

|

1544 Discussions

|

  • + 0 comments

    not sure what is trrying to be taught about sets here... with counter or dict/hashmap it's simple:

    lines = sys.stdin.read().splitlines()
    
    k = lines[0]
    rm_number_counts = {}
    for i in lines[1].split(' '):
        if i not in rm_number_counts:
            rm_number_counts[i] = 1
        else:
            rm_number_counts[i] += 1
    
    for k, v in rm_number_counts.items():
        # print(k , v)
        if v == 1:
            print(k)
    
  • + 0 comments
    from collections import Counter
    
    k, A = input(), list(map(int, input().split()))
    for item in dict(Counter(A)).items():
        if item[1] == 1:
            print(item[0])
        
    
  • + 1 comment

    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])
    
  • + 0 comments

    using two sets

    a = int(input()) datas = list(map(int,input().split())) seta = set() setb = set() for each in datas: if each not in seta: seta.add(each) setb.add(each) else: #print(each) setb.discard(each)

    print(setb.pop())

  • + 0 comments

    i = int(input())

    list_1 = list(map(int,input().split()))

    list_1.sort()

    x = 0

    while x < len(list_1) - 1:

    if list_1[x] != list_1[x + 1]:
    
        print(list_1[x])
        break
    else:
    
        x += i  # Skip over group
    

    else:

    # If captain is at the end
    print(list_1[-1])