We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Sets
- The Captain's Room
- Discussions
The Captain's Room
The Captain's Room
Sort by
recency
|
1535 Discussions
|
Please Login in order to post a comment
Dictionary Solution
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)
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!
For Python3 Platform
How does this fail only Test Case 1?!
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`