Skip to content

Category Archives: Greedy

Given two strings A and B of length N and M respectively, the task is to find the minimum cost to convert string A to… Read More
Given an array position[] consisting of N integers where position[i] denotes the position of the ith element, the task is to find the minimum cost… Read More
Given a string S of size N and a positive integer K ( where N % K = 0), the task is to find the… Read More
Given a matrix arr[][] of dimensions N * M where each cell consists of characters ‘R’ or ‘D’ except the cell arr[N][M] which contains ‘F’.… Read More
Given two integers X and Y and a binary array arr[] of length N whose first and last element is 1, the task is to… Read More
Given an array, arr[] of size N, the task is to find the maximum possible sum of array elements by alternating the signs of adjacent… Read More
Given string str, the task is to find the minimum count of characters that need to be deleted from the string such that the frequency… Read More
Given an array, arr[] of size N (always even), the task is to construct a new array consisting of N non-zero integers such that the… Read More
Given a square matrix, mat[][] of dimensions N * N, the task is find the maximum sum of diagonal elements possible from the given matrix… Read More
Given integers N, L and R, the task is to generate a Bitonic Sequence of length N from the integers in the range [L, R]… Read More
Given two strings S and T of length N and M respectively, the task is to count the number of ways of obtaining same-length substring… Read More
Given a string str, consisting of lowercase alphabets, the task is to find the shortest string which is not a subsequence of the given string.… Read More
Given a matrix arr[][] of dimensions N * M, consisting of ‘O’ or ‘F’, where ‘O’ denotes obstacles and ‘F’ denotes free spaces, the task… Read More
Given a string S and an integer K, the task is to generate lexicographically the largest string possible from the given string, by removing characters… Read More
Given two sorted arrays A[] and B[] of size N, the task is to check if it is possible to merge two given sorted arrays… Read More