Some methods to solve problem related to arrays in Ruby