CC--InterviewProblem
CC--InterviewProblem copied to clipboard
just a small mistake in the second while loop
#include
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ scanf("%d%d",&n,&q); for(int i = 0; i < n; ++ i) scanf("%d",&a[i]); while(q --){ scanf("%d",&d); dq.clear(); int ans = INT_MAX; for(int i = 0; i < n; ++ i){ while(dq.size() && a[dq.back()] < a[i]) dq.pop_back(); dq.push_back(i); while(dq.size() && dq.front() <= i - d) **// here you have to compare the index and not the value ** dq.pop_front(); if(i >= d - 1 ){ ans = min(ans, a[dq.front()]); } } printf("%d\n",ans); } return 0; }
//the rest of the code is fine