# Category Archives: Greedy

## Count of substrings formed using a given set of characters only

Given a string str and an array arr[] of K characters, the task is to find the number of substrings of str that contains characters… Read More »

## Minimum increment/decrement operations required to make Median as X

Given an array A[] of n odd integers and an integer X. Calculate the minimum number of operations required to make the median of the… Read More »

## Minimum sum obtained by choosing N number from given N pairs

Given an array arr[] of N pairs of integers (A, B) where N is even, the task is to find the minimum sum of choosing… Read More »

## Final direction after visiting every cell of Matrix starting from (0, 0)

Given a 2D grid of size N x M. The task is to find the final direction after visiting every cell under given conditions. You… Read More »

## Check given string is oddly palindrome or not | Set 2

Given string str, the task is to check if characters at the odd indexes of str form a palindrome string or not. If not then… Read More »

## Find two numbers with sum N such that neither of them contains digit K

Given a number N and a digit K (1 < K <= 9), the task is to find two integers A and B such that… Read More »

## Find number of pairs (x, y) in an Array such that x^y > y^x | Set 2

Given two arrays X[] and Y[] of positive integers, find the number of pairs such that x^y > y^x where x is an element from… Read More »

## Remove minimum characters from string to split it into three substrings under given constraints

Given a string str of lowercase alphabets, the task is to remove minimum characters from the given string so that string can be break into… Read More »

## Program for Best Fit algorithm in Memory Management using Linked List

Best fit algorithm for memory management: The memory partition in which there is a minimum loss on the allocation of the process is the best-fit… Read More »

## Number of times an array can be partitioned repetitively into two subarrays with equal sum

Given an array arr[] of size N, the task is to find the number of times the array can be partitioned repetitively into two subarrays… Read More »

## Create an array of size N with sum S such that no subarray exists with sum S or S-K

Given a number N and an integer S, the task is to create an array of N integers such that sum of all elements equals… Read More »

## Length of longest connected 1’s in a Binary Grid

Given a grid of size N*M consists of 0 and 1 only, the task is to find the length of longest connected 1s in the… Read More »

## Minimize difference after changing all odd elements to even

Given an array arr[] of N positive integers. We have to perform one operation on every odd element in the given array i.e., multiply every… Read More »

## Maximize the sum of modulus with every Array element

Given an array A[] consisting of N positive integers, the task is to find the maximum possible value of: F(M) = M % A +… Read More »

## Minimum total sum from the given two arrays

Given two arrays A[] and B[] of N positive integers and a cost C. We can choose any one element from each index of the… Read More »