Skip to content

Instantly share code, notes, and snippets.

@sharmaabhinav
Created October 7, 2015 05:18
Show Gist options
  • Select an option

  • Save sharmaabhinav/b36f581dd5c80ea677b1 to your computer and use it in GitHub Desktop.

Select an option

Save sharmaabhinav/b36f581dd5c80ea677b1 to your computer and use it in GitHub Desktop.
Solution to a hacker earth problem
# 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