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)
For Python3 Platform
How does this fail only Test Case 1?!