In sliding window technique, we maintain a window that satisfies the problem constraints. The window is unstable if it violates the problem constraints and it tries stabilize by increasing or decreasing it’s size.
Below are some of commonly asked interview questions that uses sliding window technique –
Given a string and a positive number k, find the longest substring of given string containing k distinct characters. If k is more than number of distinct characters in the string, return the whole string.
Find all substrings of a string that contains all characters of another string. In other words, find all substrings of first string that are anagrams of second string.
Given a string, find the longest substring of given string containing distinct characters.
Given a binary array, find the index of 0 to be replaced with 1 to get maximum length sequence of continuous ones.
5. Find the maximum sequence of continuous 1’s that can be formed by replacing at-most k zeroes by ones
Given an Boolean array, find the maximum sequence of continuous 1’s that can be formed by replacing at-most k zeroes by ones.
Given an array of integers, find minimum sum sub-array of given size k.
Given an array of integers, find a sub-array having given sum in it.
Given an array of integers, find the length of smallest subarray whose sum of elements is greater than the given positive number.
Given an array and an integer k, find the count of distinct elements in every sub-array of size k in the array.
Given an array of integers, print all maximum size sub-arrays having all distinct elements in them.
Given an array of sorted integers which may have several duplicates elements, count the number of distinct absolute values in the array.
Thank you for being with us. 🙂
Like us? Please spread the word and help us grow. Happy coding 🙂