• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
March 20, 2024 |850 Views
SDE Sheet - Maximum of all subarrays of size k
  Share  1 Like
Description
Discussion

This video is part of Stack and Queue section under GFG SDE Sheet.

In this problem, we are given an array arr[] of size N and an integer K. Find the maximum for each and every contiguous subarray of size K.

Example :

Input:
N = 9, K = 3
arr[] = 1 2 3 1 4 5 2 3 6
Output: 
3 3 4 5 5 5 6 
Explanation: 
1st contiguous subarray = {1 2 3} Max = 3
2nd contiguous subarray = {2 3 1} Max = 3
3rd contiguous subarray = {3 1 4} Max = 4
4th contiguous subarray = {1 4 5} Max = 5
5th contiguous subarray = {4 5 2} Max = 5
6th contiguous subarray = {5 2 3} Max = 5
7th contiguous subarray = {2 3 6} Max = 6

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-
Article: https://www.geeksforgeeks.org/sliding-window-maximum-maximum-of-all-subarrays-of-size-k/
Problem: https://www.geeksforgeeks.org/problems/maximum-of-all-subarrays-of-size-k3101/1
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

Read More