Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given an array aa, a sliding window of size kk is moving from the very left of the array to the very right. Each time

Given an array aa, a sliding window of size kk is moving from the very left of the array to the very right. Each time the sliding window moves right by one position. For each sliding window position return minimum value of all numbers inside the sliding window.

Implement a function sliding_window_min(a, k) which returns a list of minimums for each sliding window position.

Input data:

First line consists of two numbers: nn - array size (n150000n150000) and kk (k10000k10000). Second line consists of nn numbers - array aa.

Output data:

Minimums in separate lines.

Example:

Input:Input:

6 3

1 3 4 5 2 7

Output:Output:

1

3

2

2

To satisfy time limit for this task your solution has to work for O(n)O(n) . To find hints how to achieve this time complexity estimation watch again screencast about queue implementation and think about how to use queue for this task and how to extract minimum from queue for O(1)O(1) .

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

5. What is the purpose of ICAO?

Answered: 1 week ago

Question

Explain the factors affecting dividend policy in detail.

Answered: 1 week ago

Question

Explain walter's model of dividend policy.

Answered: 1 week ago