You are viewing a single comment's thread. Return to all comments →
def solve(arr: Array[Int], queries: Array[Int]): Array[Int] = { val dq = scala.collection.mutable.ArrayDeque.empty[Int] queries.map{ q => { var minOfMax = Int.MaxValue dq.clear() arr.indices.foreach{ i => { while (dq.nonEmpty && i >= q && dq.head <= i-q ) dq.removeHead() while (dq.nonEmpty && arr(dq.last) <= arr(i)) dq.removeLast() dq.append(i) if (i >= q-1) minOfMax = arr(dq.head).min(minOfMax) }} minOfMax }}
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 →