# Category Archives: Greedy

## Maximum Subset Sum possible by negating the entire sum after selecting the first Array element

Given an array A[] consisting of N integers, the task is to find the maximum subset sum possible if sum of all the element is… Read More »

## Minimize cost to Swap two given Arrays

Given two arrays A[] and B[] both of size N consisting of distinct elements, the task is to find the minimum cost to swap two… Read More »

## Construct an Array of Strings having Longest Common Prefix specified by the given Array

Given an integer array arr[] of size N, the task is to construct an array consisting of N+1 strings of length N such that arr[i]… Read More »

## Minimize swaps required to maximize the count of elements replacing a greater element in an Array

Given an array A[], consisting of N elements, the task is to find the minimum number of swaps required such that array elements swapped to… Read More »

## Permutation of Array such that products of all adjacent elements are even

Given an array arr[] consisting of N positive integers, the task is to find any permutation of given array such that the product of adjacent… Read More »

## Find a pair in Array with second largest product

Given an array arr[] of N integers, where N > 2, the task is to find the second largest product pair from the given array.… Read More »

## Maximize length of Subarray of 1’s after removal of a pair of consecutive Array elements

Given a Binary array arr[] consisting of N elements, the task is to find the maximum possible length of subarray of only 1’s, after deleting… Read More »

## Minimum number of steps required to obtain the given Array by the given operations

Given an array arr[] of N positive integers, the task is to find the minimum number of operations required of the following types to obtain… Read More »

## Construct a Matrix with no element exceeding X and sum of two adjacent elements not exceeding Y

Given four integers N, M, X and Y, the task is to construct a N * M matrix such that each cell consists of a… Read More »

## Maximize GCD of all possible pairs from 1 to N

Given an integer N (? 2), the task is to find the maximum GCD among all pairs possible by the integers in the range [1,… Read More »

## Queries to find the Minimum Weight from a Subtree of atmost D-distant Nodes from Node X

Given an N-ary Tree rooted at 1, and an array val[] consisting of weights assigned to every node, and a matrix Q[][], consisting of queries… Read More »

## Travelling Salesman Problem | Greedy Approach

Given a 2D matrix tsp[][], where each row has the array of distances from that indexed city to all the other cities and -1 denotes… Read More »

## Rearrange an Array such that Sum of same-indexed subsets differ from their Sum in the original Array

Given an array A[] consisting of N distinct integers, the task is to rearrange the given array such that the sum of every same-indexed non-empty… Read More »

## Maximize count of Decreasing Consecutive Subsequences from an Array

Given an array arr[] consisting of N integers, the task is to find the maximum count of decreasing subsequences possible from an array which satisfies… Read More »

## Minimum count of elements required to obtain the given Array by repeated mirror operations

Given an array arr[] consisting of N integers, the task is to find the array K[] of minimum possible length such that after performing multiple… Read More »