Skip to content

Tag Archives: sliding-window

Given an array, find the subarray (containing at least k numbers) which has the largest sum. Examples:   Input : arr[] = {-4, -2, 1, -3} k… Read More
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
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 start… Read More
Given an array of integers and a number k, find the maximum sum of a subarray of size k.  Examples:  Input : arr[] = {100,… Read More
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
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
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
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
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
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
Given an unsorted array of nonnegative integers, find a continuous subarray which adds to a given number. Examples :  Input: arr[] = {1, 4, 20, 3,… Read More
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
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