# Category Archives: Greedy

Given an array B[] of length N, the task is to print an array A[] such that for every ith element B[i] is gcd of… Read More
Given an array A[] of size N where each element A[i] =max(P, P, . . ., P[i]), where P[] is a permutation consisting of elements… Read More
Given positive integers N, A, B and C such that 1 ≤ C < N. The task is to maximize the value of B by… Read More
Given a string S of size N consisting of characters ‘0’ to ‘9’, the task is to print the longest palindrome that can be formed… Read More
Given a binary string S of length N and an integer X, the task is to check if there exists a right-wise circular rotation of… Read More
Given a permutation A[] of first N integers (i.e. array contains integers from 1 to N exactly once) and an integer K, the task is… Read More
Given an array Arr[] of size N, the cost of removing ith element is Arr[i]. The task is to remove the maximum number of elements… Read More
Given an array A, the task is to find elements with the occurrence at least K times the frequency of the least occurring element in… Read More
Given a string S consisting of only lowercase English letters of length N, the task is to find the count of substrings such that each… Read More
Given a number N, the task is to find the minimum number X such that A(X) = N, where A(X) for positive integer X is… Read More
Given an integer array A[] of length N (N >= 1), the task is to print the total number of indices in the array that… Read More
Given two integers L and R, construct an array of given size N such that the GCD (Greatest Common Divisor) of the element with their… Read More
Given an array arr[] of size N, the task is to find the minimum moves to segregate even and odd numbers by swapping two adjacent… Read More
Given an array A[] of size N, the task is to maximize the frequency of any element by adding any positive integer X to all… Read More
Given an array A[] of N integers, the task is to find the lexicographically smallest subsequence of the array by deleting all the occurrences of… Read More