Hackerrank Day 1: Interquartile Range



My Solution in Ruby:


We can also store the elements and their corresponding frequencies in their own hash, which are stored in an array, and sort the array by the value of the element in the hashes, like so:


  • It’s possible to store hashes within an array.
  • sort! modifies current existing array.  sort creates a new sorted array.
    • array.sort!{ |x, y| x <=> y }  sorts current array in ascending order.
    • array.sort!{ |x, y| y <=> x }  sorts current array in descending order.
  • Array.new that takes two arguments (n, element) returns that element n times.
    • Array.new(3, true) #=> [true, true, true]


Hackerrank Day 1: Interquartile Range

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s