# Category Archives: Greedy

## Largest subset having with sum less than equal to sum of respective indices

Given an array arr[], the task is to find the length of the largest subset with the sum of elements less than or equal to… Read More »

## Count of unique palindromic strings of length X from given string

Given a string s and an integer X, our task is to find the number of distinct palindromic strings of length X from the given… Read More »

## Maximum possible Array sum after performing given operations

Given array arr[] of positive integers, an integer Q, and arrays X[] and Y[] of size Q. For each element in arrays X[] and Y[],… Read More »

## Min operations to reduce N to 1 by multiplying by A or dividing by B

Given a number N and two integers A and B, the task is to check if it is possible to convert the number to 1… Read More »

## Min operations to reduce N by multiplying by any number or taking square root

Given a number N, the task is to find the minimum value of N by applying below operations any number of times:  Multiply N by… Read More »

## Minimum distance between any most frequent and least frequent element of an array

Given an integer array arr[] of size N, the task is to find the minimum distance between any most and least frequent element of the… Read More »

## Check if frequency of each element in given array is unique or not

Given an array arr[] of N positive integers where the integers are in the range from 1 to N, the task is to check whether… Read More »

## Print all numbers in given range having digits in strictly increasing order

Given two postive integers L and R, the task is to print the numbers in the range [L, R] which have their digits in strictly… Read More »

## Maximum value of Bitwise AND from root to leaf in a Binary tree

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

## Construct a string that has exactly K subsequences from given string

Given a string str and an integer K, the task is to find a string S such that it has exactly K subsequences of given… Read More »

## Replace each element of Array with it’s corresponding rank

Given an array arr[] of N integers, the task is to replace each element of Array with their rank in array. The rank of an… Read More »

## Sum of first N natural numbers with all powers of 2 added twice

Given an integer N, the task is to calculate the sum of first N natural numbers adding all powers of 2 twice to the sum.Examples: … Read More »

## Largest subset with M as smallest missing number

Given an array arr[] of N positive integers and a positive integer M, the task is to find the length of longest subset whose smallest… Read More »

## Check if a decreasing Array can be sorted using Triple cyclic shift

Given an arr[] of size N whose elements are sorted in descending order. The task is to find if the given array can be sorted… Read More »

## Rearrange an array such that product of every two consecutive elements is a multiple of 4

Given an array arr[] of size N, the task is to rearrange the array elements such that for every index i(1 <= i <= N… Read More »