You are viewing a single comment's thread. Return to all comments →
Good idea, I use your algorithm to solve this. But i change a little bit after getting the incremental heights.
#!/bin/ruby def get_sum_of_stacks(*stacks) ary = [] stacks.each do |stack| a = [] b = 0 stack.reverse.each_with_index{|i, index| a[index] = (b += i)} ary << a end ary end def get_answer(*heights) a = heights.flatten.group_by(&:itself) a = a.select{|k,v| v.size == 3}.max print a.nil? ? 0 : a[0] end n1,n2,n3 = gets.strip.split(' ') n1 = n1.to_i n2 = n2.to_i n3 = n3.to_i h1 = gets.strip h1 = h1.split(' ').map(&:to_i) h2 = gets.strip h2 = h2.split(' ').map(&:to_i) h3 = gets.strip h3 = h3.split(' ').map(&:to_i) h1,h2,h3 = get_sum_of_stacks(h1,h2,h3) get_answer(h1,h2,h3)
not sure if it's faster
Seems like cookies are disabled on this browser, please enable them to open this website
Equal Stacks
You are viewing a single comment's thread. Return to all comments →
Good idea, I use your algorithm to solve this.
But i change a little bit after getting the incremental heights.
not sure if it's faster