Created
February 15, 2018 02:33
-
-
Save basmoura/0dbbb737fc01bb28acf2a7a4d311e06a to your computer and use it in GitHub Desktop.
This file contains 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
array = Array.new(100) { rand(1...5000) } | |
def dp(array) | |
duplicates = {} | |
array.each do |a| | |
if duplicates[a] | |
duplicates[a] += 1 | |
else | |
duplicates[a] = 1 | |
end | |
end | |
duplicates.sort_by { |k,v| v }.reverse | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment