If you haven’t looked at my previous post on Binary Search, then please have a look at it. Sliding Window comes in handy when attending any coding Interview in any of the big giant MNC’s(FAANG). I have encountered these patterns many times in my past coding interviews.

- This method is usually used in array/list, whenever you are asked to calculate anything like minimum or maximum of continues subsets of an array of fixed length.
- This consists of calculating a value for the given length by moving our widow element by element until we reach the array end.

Let’s consider a question and see how we solve it in

OLD SCHOOLway and how sliding window makes it much better. …

Binary Search is one of the most commonly asked questions in any technical interviews in top MNC’s. The basic idea is that, given an array/list with sorted elements, you have to find a certain element in it, the algorithm is based on a well know domain **divide and conquer technique**. It repeatedly breaks down the array in two sub-arrays which might contain the element we need and discards the other sub-array, and this goes on till the array size becomes 0 or till the element is found!

Let me clear out the common doubts you might get, but before that try to understand the basic ideology in binary search, if you observe, initially low=0(first element) and high=array_size(last element), so basically in the first iteration we are considering the window size of the full array and on each iteration based on the middle element we consider a single sub-array of half-length and omit the other half as you can see in the code. …

About