We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
And the same approach in ruby -- I claim no credit for working this out -- I wrote this after reading the comments and code posted here.
Just thought I'd add a ruby solution for anyone looking for one.
N,M=gets.chomp.split(' ').map(&:to_i)# create array of zeros of length N + 1arr=Array.new(N+1,0)M.timesdo# cycle through and get the inputsstart,finish,value=gets.chomp.split(' ').map(&:to_i)# increment value at start of sequencearr[start-1]+=value# decrement value at first position after sequencearr[finish]-=valueendtmp=0max=0arr.eachdo|value|# step through summing arraytmp+=value# capture the max value of tmpmax=tmpifmax<tmpendputsmax
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
And the same approach in ruby -- I claim no credit for working this out -- I wrote this after reading the comments and code posted here.
Just thought I'd add a ruby solution for anyone looking for one.