# Category Archives: Greedy

## Minimize subarray increments/decrements required to reduce all array elements to 0

Given an array arr[], select any subarray and apply any one of the below operations on each element of the subarray: Increment by one Decrement… Read More »

## Substring of length K having maximum frequency in the given string

Given a string str, the task is to find the substring of length K which occurs the maximum number of times. If more than one… Read More »

## Count ways to generate pairs having Bitwise XOR and Bitwise AND equal to X and Y respectively

Given two integers X and Y, the task is to find the total number of ways to generate a pair of integers A and B… Read More »

## Rearrange an array to make similar indexed elements different from that of another array

Given two sorted arrays A[] and B[] consisting of N distinct integers, the task is to rearrange the elements of array B[] such that, for… Read More »

## Make all array elements equal by repeated subtraction of absolute difference of pairs from their maximum

Given an array arr[] consisitng of N integers, the task is to make all array elements equal by selecting any pair of integers from the… Read More »

## Swap the elements between any two given quadrants of a Matrix

Given a matrix, mat[][] of size N * M, where N and M is always even, and two integers X and Y, the task is… Read More »

## Maximize the sum of Kth column of a Matrix

Given two integers N and K, the task is to maximize the sum of the Kth column of N * N row-wise sorted matrix consisting… Read More »

## Check if any permutation of array contains sum of every adjacent pair not divisible by 3

Given an array arr[] consisting of N integers, the task is to check if any permutation of the array elements exists where the sum of… Read More »

## Maximized partitions of a string such that each character of the string appears in one substring

Given a string S, split the given string into as many substrings as possible such that each character from the given string appears in a… Read More »

## Lengths of maximized partitions of a string such that each character of the string appears in one substring

Given string str of lowercase alphabets, split the given string into as many substrings as possible such that each character from the given string appears… Read More »

## Check if a number is a perfect square having all its digits as a perfect square

Given an integer N, the task is to check if the given number is a perfect square having all its digits as a perfect square… Read More »

## Check if a number can be represented as sum of two consecutive perfect cubes

Given an integer N, the task is to check if this number can be represented as the sum of two consecutive perfect cubes or not.… Read More »

## Count substrings with different first and last characters

Given a string S, the task is to print the count of substrings from a given string whose first and last characters are different. Examples:… Read More »

## Minimize characters to be changed to make the left and right rotation of a string same

Given a string S of lowercase English alphabets, the task is to find the minimum number of characters to be changed such that the left… Read More »

## Minimum size substring to be removed to make a given string palindromic

Given a string S, the task is to print the string after removing the minimum size substring such that S is a palindrome or not.… Read More »