HackerRank Python - The Captains Room

Mr. Anant Asankhya is the manager at the INFINITE hotel. The hotel has an infinite amount of rooms.

One fine day, a finite number of tourists come to stay at the hotel.
The tourists consist of:
→ A Captain.
→ An unknown group of families consisting of K members per group where K ≠ 1.

The Captain was given a separate room, and the rest were given one room per group.

Mr. Anant has an unordered list of randomly arranged room entries. The list consists of the room numbers for all of the tourists. The room numbers will appear K times per group except for the Captain's room.

Mr. Anant needs you to help him find the Captain's room number.
The total number of tourists or the total number of groups of families is not known to you.
You only know the value of K and the room number list.

  1. # Enter your code here. Read input from STDIN. Print output to STDOUT
  2. k = int(input())
  3. room_number_list = list(map(int,input().split()))
  4. room_number_set = set(room_number_list)
  5. room_number_list_sum = sum(room_number_list)
  6. room_number_set_sum = sum(room_number_set) * k
  7. diff = room_number_set_sum - room_number_list_sum
  8. for i in room_number_set:
  9. if diff == ((k-1)*i):
  10. print(i)
  11. break

download android app