![]() |
When we are dealing with problems that require checking answers of some ranges in an array, the Sliding window algorithm can be a very powerful technique. What are Sliding Window Problems?
Follow the Sliding Window Technique post to learn more about this algorithm. Key Points to Identify Sliding Window Problems:
In this following article, we’ll explore the different patterns where we can apply the sliding window technique with the help of problems and examples. There are generally two categories of Sliding window problems:
Fixed Size Sliding Window
For example: Given an array of integers and a number K, find the maximum sum of a subarray of size K. Post Link: Click Here Intuition: In this question we already given the size of the subarray we just have to iterate in the array and calculate the sum of each subarray of size k with sliding window technique. Similar problems following same approach:
For example: Maximum subarray size, such that all subarrays of that size have sum less than K. Post Link: Click Here Intuition: In this question we have to find the maximum size of the subarray which satisfy the given condition. In these type of questions we can apply Binary Search on Answer + Sliding Window to solve the question, We can find our possible size of subarray by applying binary search on subarray size and find the condition validation using sliding window of fixed size K , which will be equal to mid value in Binary Search. Similar problems following same approach:
Variable Size Sliding Window Problem
For example: Find length of the longest substring without repeating characters. Post Link: Click Here Intuition: To solve the problems based on the above category follow the below intuition steps:
Similar problems following same approach:
Other problems based on Sliding Window:Link for Practice Problems of Sliding Window |
Reffered: https://www.geeksforgeeks.org
Arrays |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |