Welcome to the daily solving of our PROBLEM OF THE DAY with Karan Mashru We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Sliding-window but also build up problem-solving skills.
Given an array arr[] and an integer k. Find the maximum for each and every contiguous subarray of size k.
Examples:
Input: arr[] = [1, 2, 3, 1, 4, 5, 2, 3, 6], k = 3
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
Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/maximum-of-all-subarrays-of-size-k3101/1