# Category Archives: Greedy

## Check whether there exists a triplet (i, j, k) such that arr[i] < arr[k] < arr[j] for i < j < k

Given an array arr[], the task is to check that if there exist a triplet (i, j, k) such that arr[i]<arr[k]<arr[j] and i<j<k then print… Read More »

## Arrange the numbers in the Array as per given inequalities

Given a list of N distinct integers and a list of N-1 inequality signs, the task is to insert the integers between the inequality signs,… Read More »

## Array formed using sum of absolute differences of that element with all other elements

Given a sorted array arr[] of N distinct positive integers. The task is to generate an array such that the element at each index in… Read More »

## Print all possible ways to write N as sum of two or more positive integers

Given an integer N, the task is to print all the possible ways in which N can be written as the sum of two or… Read More »

## Minimum number of distinct elements after removing M items | Set 2

Given an array of items, an ith index element denotes the item id’s, and given a number m, the task is to remove m elements… Read More »

## Find the Mth element of the Array after K left rotations

Given non-negative integers K, M, and an array arr[] with N elements find the Mth element of the array after K left rotations. Examples: Input:… Read More »

## Find minimum moves to bring all elements in one cell of a matrix

Given a matrix mat[][], pair of indices X and Y, the task is to find the number of moves to bring all the non-zero elements… Read More »

## Check if the given string is linear or not

Given a string str, the task is to check whether the given string is linear or not. If it is linear then print “Yes” else… Read More »

## Minimize cost to color all the vertices of an Undirected Graph

Given an Undirected Graph consisting of N vertices and M edges, where node values are in the range [1, N], and vertices specified by the… Read More »

## Count subarrays having sum of elements at even and odd positions equal

Given an array arr[] of integers, the task is to find the total count of subarrays such that the sum of elements at even position… Read More »

## Find maximum GCD value from root to leaf in a Binary tree

Given a Binary Tree, the task is to find the maximum value of GCD from any path from the root node to the leaf node.… Read More »

## Check if given string is a substring of string formed by repeated concatenation of z to a

Given a string str, the task is to check if string str is a substring of an infinite length string S in which lowercase alphabets… Read More »

## Maximize count of Decreasing Subsequences from the given Array

Given an array arr[], the task is to rearrange the array to generate maximum decreasing subsequences and print the count of the maximum number of… Read More »

## Minimum cost to reduce the integer N to 1 as per given conditions

Given four integers N, X, P, and Q, the task is to find the minimum cost to make N to 1 by the following two… Read More »

## Minimum steps for increasing and decreasing Array to reach either 0 or N

Given an integer N and two arrays increasing[] and decreasing[], such that they have elements from 1 to N only. The task is to find… Read More »