You are viewing a single comment's thread. Return to all comments →
Sliding window implemented in Ruby:
def getMiniMax(arr, d) startWindow = 0 endWindow = d - 1 window = nil max = nil miniMax = nil until endWindow == arr.length if window.nil? window = arr[startWindow..endWindow] max = window.max miniMax = max else shifted = window.shift pushed = arr[endWindow] window.push(pushed) if pushed >= max max = pushed elsif shifted == max max = window.max if max < miniMax miniMax = max end end end startWindow +=1 endWindow += 1 end return miniMax end
Seems like cookies are disabled on this browser, please enable them to open this website
Queries with Fixed Length
You are viewing a single comment's thread. Return to all comments →
Sliding window implemented in Ruby: