Created
October 7, 2015 05:18
-
-
Save sharmaabhinav/b36f581dd5c80ea677b1 to your computer and use it in GitHub Desktop.
Solution to a hacker earth problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Logic : first create list of all players and then remove loosers from that. Using a hash it can be done in O(n) time. | |
| no_of_inputs = 2 ** gets.chomp.to_i - 1 | |
| player_list = Hash.new | |
| inputs = []; | |
| 1.upto(no_of_inputs) do | |
| player1,player2 = gets.split(" ") | |
| inputs.push([player1, player2]) | |
| player_list[player1] = player_list[player2] = 1 | |
| end | |
| inputs.each do |input| | |
| player_list[input[1]] = -1 | |
| end | |
| player_list.each do |player, state| | |
| print player if state == 1 | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment