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.
vector<int>solve(vector<int>arr,vector<int>queries){vector<int>res;intN=arr.size();for(inti=0;i<queries.size();i++){intd=queries[i];vector<int>q;intmini=INT32_MAX;for(intj=0;j<N;j++){// q is a decreasing vectorwhile(!q.empty()&&q.back()<arr[j]){q.pop_back();}q.push_back(arr[j]);if(j+1>=d){if(mini>q[0]){mini=q[0];}if(q[0]==arr[j+1-d]){q.erase(q.begin());}}}res.push_back(mini);}returnres;}
Cookie support is required to access HackerRank
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 →
Clean solution in C++