The Captain's Room

Sort by

recency

|

1535 Discussions

|

  • + 0 comments

    Dictionary Solution

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    n = int(input())
    
    rooms = list(map(int,input().split()))
    
    # print(n)
    counts = {}
    for _ in rooms:
        counts[_] = counts.get(_,0)+1
    print(min(counts,key=counts.get))
    
  • + 0 comments
    from collections import Counter
    k=int(input())
    rn=input().split()
    l=dict(Counter(rn))
    for k,v in l.items():
            if v==1:print(int(k))
    
  • + 1 comment

    Enter your code here. Read input from STDIN. Print output to STDOUT

    k=int(input()) list_k=list(map(int,input().split()))

    Use set to get the unique value in the list

    room_set = set(list_k)

    now we are multiplying sum of the set with k first

    then we are subtracting it with the original list's sum (so that only the captains value*(k-1) remains)

    then we are dividing by (k-1) to get the actual value

    captain_room = (sum(room_set)*k - sum(list_k)) // (k-1)

    print(captain_room)

    • + 0 comments

      Wow bro, great answer, and here you are, going through the whole list. It's definitely worth knowing about algebra. This makes me realize how little I know about math. Thanks for your input, bro!

  • + 0 comments

    For Python3 Platform

    k = int(input())
    room_numbers = input().split()
    unique_room_numbers = set(room_numbers)
    
    for num in unique_room_numbers:
        room_numbers.remove(num)
        
        if(num not in room_numbers):
            print(int(num))
            break
    
  • + 1 comment

    How does this fail only Test Case 1?!

    from collections import Counter
    
    K = int(input())
    rooms = list(Counter(map(int,input().split())))
    
    print(rooms[-1])
    
    • + 0 comments

      Apparently this works? This follows the same exact logic....

      from collections import Counter

      _ = int(input()) rooms = Counter(map(int,input().split()))

      for element,count in reversed(rooms.items()): if (count == 1): print(element) break`