https://www.hackerrank.com/challenges/deque-stl/problem
Mam timeout a już nie wiem co robić, jak zoptymalizować
Z góry dziękuję za pomoc
void printKMax(int A[], int n, int k)
{
//Write your code here.
std::deque<int> deqWindow;
deqWindow.push_back(A[0]);
auto maxIndex = 0;
for(int i = 1; i < n; ++i)
{
if(deqWindow.size() == k)
{
std::cout<<deqWindow[maxIndex]<<' ';
deqWindow.pop_front();
--maxIndex;
if(maxIndex < 0)
{
maxIndex = 0;
for(int ih = 1; ih < deqWindow.size(); ++ih)
{
if(deqWindow[maxIndex] < deqWindow[ih])
{
maxIndex = ih;
}
}
}
}
if(deqWindow[maxIndex] < A[i])
{
maxIndex = deqWindow.size();
}
deqWindow.push_back(A[i]);
}
std::cout<<deqWindow[maxIndex]<<'\n';
}