The Captain's Room

Sort by

recency

|

1542 Discussions

|

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

    I tried using set since it is from the sets section. Time is exceeding limit, anyone who can optimize this. N=int(input()) m=list(map(int, input().split())) n=set(m) l=[] for i in n: count=0 for j in m: if i==j: count +=1 l.append([i,count])

    for i in l: if i[1]==1: print(i[0])

  • + 0 comments

    Here is HackerRank The Captain's Room in Python solution - https://programmingoneonone.com/hackerrank-the-captains-room-solution-in-python.html