The Captain's Room in

The Captain's Room in

Hello Friends, How are you? Today I am going to solve the HackerRank The Captain’s Room Problem in Python with a very easy explanation. In this article, you will get one or more approaches to solving this problem. So let’s start- {tocify} $title={Table of Contents} 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. → 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. The first line consists of an integer, K, the size of each group. The second line contains the unordered elements of the room number list. Output the Captain’s room number.

chris alan {codeBox}

Chris Alan {codeBox}

The list of room numbers contains 31 elements. Since K is 5, there must be 6 groups of families. In the given list, all of the numbers repeat 5 times except for room number 8. Hence, 8 is the Captain’s room number. Approach I: The Captain’s Room HackerRank Python Solution

# ========================
# Information
# ======================== # Name: The Captain's Room in Python HackerRank
# Direct Link: https://www.hackerrank.com/challenges/py-the-captains-room/problem
# Difficulty: Easy
# Max Score: 10
# Language: Pypy 3 # ========================
# Solution Start
# ======================== #The Captain's Room in Python - Hacker Rank Solution # Enter your code here. Read input from STDIN. Print output to STDOUT N = int(input()) storage = map(int, input().split())
storage = sorted(storage) for i in range(len(storage)): if(i != len(storage)-1): if(storage[i]!=storage[i-1] and storage[i]!=storage[i+1]): print(storage[i]) break; else: print(storage[i]) #The Captain's Room in Python - Hacker Rank Solution END
# MyEduWaves
No Comments

Sorry, the comment form is closed at this time.