You are viewing a single comment's thread. Return to all comments →
Hi, I have written code in Ruby. It works fine in my local but here it says wrong answer for test case 4
def solve(arr) count = 0 arr.each_with_index do |a,i| count +=1 j = i+1 while j <= arr.length - 1 break if arr[j] < a if arr[j] > arr[j-1] && arr[j] > a count = count + 1 j = j + 1 elsif arr[j] < arr[j-1] next_big_elem = arr[j..arr.length - 1].select{|x| x if x>arr[j-1]}.first if next_big_elem count = count + 1 j = arr.index(next_big_elem)+1 end break end end end print count count end
end
Seems like cookies are disabled on this browser, please enable them to open this website
Almost sorted interval
You are viewing a single comment's thread. Return to all comments →
Hi, I have written code in Ruby. It works fine in my local but here it says wrong answer for test case 4
end