## Sliding Window Algorithm (Track the maximum of each subarray of size k)

Objective: Given an array and integer k, write an algorithm to find the maximum element in each subarray of size k. Example: int [] nums = { 1, 2, 3, 2, 4, 1, 5,...

@tutorialhorizon

Objective: Given an array and integer k, write an algorithm to find the maximum element in each subarray of size k. Example: int [] nums = { 1, 2, 3, 2, 4, 1, 5,...

Objective: Given a String write an algorithm to print all the possible sub subsequences. Example: String input = “abc”; Output: Possible sub sequences – {Empty}, {a}, {b}, {c}, {ab} ,{a,c}, {b, c}, {a, b, c}...

Objective: Given a graph, source vertex and destination vertex. Write an algorithm to print all possible paths between source and destination. This problem also known as “Print all paths between two nodes” Example: Approach:...

Objective: Given an array write an algorithm to print all the possible sub subsequences. Example: int [] a = {1, 2, 3}; Output: Possible sub sequences – {Empty}, {1}, {2}, {3}, {1, 2} ,{1,3}, {2,...

Objective: Given a string write an algorithm to print all the possible sub strings. Example: String input = “abcd”; Output: Possible sub strings – a a b a b c a b c d b...

Objective: Given an array write an algorithm to find the sum of all the possible sub arrays. Example: int [] a = {1, 2, 3}; Output: Possible subarrays – {1}, {2}, {3}, {1, 2} ,...

Objective: Given an array write an algorithm to print all the possible sub arrays. Example: int [] a = {1, 2, 3}; Output: Possible subarrays – {1}, {2}, {3}, {1, 2} , {2, 3}, {1,...

Objective: Given a list of words and length L. Format the words so that each line will have only L characters and fully justified (left and right justified). Restrictions- You need to fit as many...

Objective: There are n number of eggs and building which has k floors. Write an algorithm to find the minimum number of drops is required to know the floor from which if egg is dropped,...

Objective: Given ‘n’ Nuts and ‘n’ Bolts of different sizes. There is one-to-one mapping between nuts and bolts. Write an algorithm to find all matches between nuts and bolts Note: This problem can also be...

Objective: Given an array of integers of size 2n, write an algorithm to arrange them such that first n elements and last n elements are set up in alternative manner. Say n = 3 and...

Objective: Given a printer which can perform only 2 operations- Printer can print consecutive identical characters in one go. It can replace consecutive characters by consecutive identical characters at any position. You are given a...

Objective: Given a string, write an algorithm to remove the duplicate characters in that string. Example: Input: tutorialhorizon Output: tuorialhzn Approaches: There are multiple approaches to solve this problem- Use Sorting – (Will change the...

Objective: Given two sorted arrays of size n. Write an algorithm to find the median of combined array (merger of both the given arrays, size = 2n). What is Median? The median is the value separating the...

Objective: Given an array of non negative integers, start from the first element and reach the last by jumping. The jump length can be at most the value at the current position in the array....

%d bloggers like this: