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.
//Write your code here.
deque<int> d(arr,arr+k); //sub array
auto max = max_element(d.begin(),d.end()); //get max of sub array
cout << *max <<" ";
//get max if max is removed
if(*max == d.front())
max = max_element(d.begin()+1,d.end());
d.pop_front(); //remove front element
for(int i=k;i<n;++i){
d.push_back(arr[i]);
//check max
if(arr[i] >= *max)
max = d.end()-1;
cout << *max <<" ";
//get max if max is removed
if(max == d.begin()){
max = max_element(d.begin()+1,d.end());
}
d.pop_front();
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Deque-STL
You are viewing a single comment's thread. Return to all comments →