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.
I had a solution which pushed and pops, but that exceeded time limits.
But the straight-forward solution below did as well. Anybody any clues?
voidprintKMax(intarr[],intn,intk){//Write your code here.std::deque<int>que;intcnt;for(cnt=0;cnt<n;cnt++)que.push_back(arr[cnt]);// just push them allfor(cnt=0;cnt<n-k;cnt++)std::cout<<*std::max_element(que.begin()+cnt,que.begin()+cnt+k)<<' ';std::cout<<*std::max_element(que.begin()+cnt,que.begin()+cnt+k)<<std::endl;}
Deque-STL
You are viewing a single comment's thread. Return to all comments →
I had a solution which pushed and pops, but that exceeded time limits. But the straight-forward solution below did as well. Anybody any clues?