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 –

#### 1. Find the longest substring of given string containing k distinct characters

*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.*

#### 2. Find all substrings of a string that are permutation of a given 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.*

#### 3. Longest substring of given string containing distinct characters

*Given a string, find the longest substring of given string containing distinct characters.*

#### 4. Find maximum length sequence of continuous ones (Using Sliding Window)

*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.*

#### 6. Find minimum sum subarray of given size k

*Given an array of integers, find minimum sum sub-array of given size k.*

#### 7. Find subarray having given sum in given array of integers

*Given an array of integers, find a sub-array having given sum in it.*

#### 8. Find the length of smallest subarray whose sum of elements is greater than the given number

*Given an array of integers, find the length of smallest subarray whose sum of elements is greater than the given positive number.*

#### 9. Find count of distinct elements in every sub-array of size k

*Given an array and an integer k, find the count of distinct elements in every sub-array of size k in the array.*

#### 10. Print all sub-arrays of an array having distinct elements

*Given an array of integers, print all maximum size sub-arrays having all distinct elements in them.*

#### 11. Count the distinct absolute values in the sorted array

*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 🙂

## Leave a Reply