K Sized Subarray Maximum solved in JS | GfG | POTD | Streak 408 | Mon, 12 Jan 2026
Автор: NewsCraft Studio (by JKS)
Загружено: 2026-01-11
Просмотров: 39
Solutions available at https://github.com/JKS-sys/Solution-T...
POTD Question was https://www.geeksforgeeks.org/problem...
K Sized Subarray Maximum
Difficulty: Medium
Accuracy: 26.04%
Submissions: 419K+
Points: 4
Given an array arr[] of positive integers and an integer k. You have to find the maximum value for each contiguous subarray of size k. Return an array of maximum values corresponding to each contiguous subarray.
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
Input: arr[] = [5, 1, 3, 4, 2], k = 1
Output: [5, 1, 3, 4, 2]
Explanation: When k = 1, each element in the array is its own subarray, so the output is simply the same array
Constraints:
1 ≤ arr.size() ≤ 10^6
1 ≤ k ≤ arr.size()
0 ≤ arr[i] ≤ 10^9
Expected Complexities:
Time Complexity: O(n)
Auxiliary Space: O(k)
#coding #GeeksforGeeks #ProblemOfTheDay #JavaScript
---
introduction:
name: "Jagadeesh Kumar S"
contact: "+91 73972 85837 | jagadeesh_2k17@proton.me"
description: "A problem-solving enthusiast passionate about coding challenges."
technical_achievements:
"Solved 100+ daily coding challenges on GeeksforGeeks"
"Ranked in the top 130 on SRM Institute of Science and Technology's GeeksforGeeks leaderboard"
"Maintained a 100+ day streak for Problem of the Day"
github:
contributions: "Solutions available at https://github.com/JKS-sys/Solution-T..."
---
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: