# Tag Archives: sliding-window

## Count subarrays having total distinct elements same as original array

Given an array of n integers. Count total number of sub-array having total distinct elements same as that of total distinct elements of original array.… Read More »

## First negative integer in every window of size k

Given an array and a positive integer k, find the first negative integer for each window(contiguous subarray) of size k. If a window does not… Read More »

## Largest sum subarray with at-least k numbers

Given an array, find the subarray (containing at least k numbers) which has the largest sum. Examples: Input : arr[] = {-4, -2, 1, -3}… Read More »

## Smallest window that contains all characters of string itself

Given a string, find the smallest window length with all distinct characters of the given string. For eg. str = “aabcbcdbca”, then the result would… Read More »

## Window Sliding Technique

This technique shows how a nested for loop in some problems can be converted to a single for loop to reduce the time complexity. Let’s… Read More »

## Find maximum (or minimum) sum of a subarray of size k

Given an array of integers and a number k, find maximum sum of a subarray of size k. Examples : Input : arr[] = {100,… Read More »

## Sum of minimum and maximum elements of all subarrays of size k.

Given an array of both positive and negative integers, the task is to compute sum of minimum and maximum elements of all sub-array of size… Read More »

## Find maximum of minimum for every window size in a given array

Given an integer array of size n, find the maximum of the minimum’s of every window size in the array. Note that window size varies… Read More »

## Count distinct elements in every window of size k

Given an array of size n and an integer k, return the count of distinct numbers in all windows of size k. Example: Input: arr[]… Read More »

## Count ways to reach the n’th stair

There are n stairs, a person standing at the bottom wants to reach the top. The person can climb either 1 stair or 2 stairs… Read More »

## Anagram Substring Search (Or Search for all permutations)

Given a text txt[0..n-1] and a pattern pat[0..m-1], write a function search(char pat[], char txt[]) that prints all occurrences of pat[] and its permutations (or… Read More »

## Smallest subarray with sum greater than a given value

Given an array of integers and a number x, find the smallest subarray with sum greater than the given value. Examples: arr[] = {1, 4,… Read More »

## Find subarray with given sum | Set 1 (Nonnegative Numbers)

Given an unsorted array of nonnegative integers, find a continuous subarray which adds to a given number. Examples : Input: arr[] = {1, 4, 20,… Read More »

## Sliding Window Maximum (Maximum of all subarrays of size k)

Given an array and an integer K, find the maximum for each and every contiguous subarray of size k. Examples : Input: arr[] = {1,… Read More »

## Find the smallest window in a string containing all characters of another string

Given two strings string1 and string2, the task is to find the smallest substring in string1 containing all characters of string2 efficiently. Examples: Input: string… Read More »