# Category Archives: Greedy

## Number of substrings with length divisible by the number of 1’s in it

Given a binary string S consisting of only 0’s and 1’s. Count the number of substrings of this string such that length of substring is… Read More »

## Find the number of elements X such that X + K also exists in the array

Given an array a[] and an integer k, find the number of elements x in this array such that the sum of x and k… Read More »

## Find subarray of Length K with Maximum Peak

Given an array arr[] of length n and a positive integer K, we have to find a subarray of length K which has maximum peak… Read More »

## Find the largest number smaller than integer N with maximum number of set bits

Given an integer N, the task is to find the largest number smaller than N having the maximum number of set bits. Examples: Input :… Read More »

## Find the size of largest group where groups are according to the xor of digits

Given an integer N and the task is to find the size of the largest group in a range 1 to N, where two numbers… Read More »

## Find length of longest substring with at most K normal characters

Given a string P consisting of small English letters and a 26-digit bit string Q, where 1 represent special character and 0 represent normal character… Read More »

## Find the String having each substring with exactly K distinct characters

Given two integers N and K. The task is to find the string of length N, such that each substring of length greater than equal… Read More »

## Find the Smallest number that divides X^X

Given a number X, find the Smallest Number, which is greater than 1, that divides XX. In the given question, X is always presumed to… Read More »

## Count the number of unordered triplets with elements in increasing order and product less than or equal to integer X

Given an array A[] and an integer X. Find the number of unordered triplets (i, j, k) such that A[i] < A[j] < A[k] and… Read More »

## Find if string is K-Palindrome or not using all characters exactly once

Given a string str and an integer K, the task is to check if it is possible to make the string K palindromes using all… Read More »

## Check if a number can be expressed as a product of exactly K prime divisors

Given an integer N, the task is to check if it can be expressed as a product of exactly K prime divisors. Examples: Input: N… Read More »

## Minimum time required to cover a Binary Array

Given an integer N which represents the size of a boolean array which is initially filled with 0, and also given an array arr[] of… Read More »

## Count of largest sized groups while grouping according to product of digits

Given an integer N, the task is to find the number of groups having the largest size. Each number from 1 to N is grouped… Read More »

## Count of subarrays having exactly K prime numbers

Given an array arr[] of N integers and a number K. The task is to count the number of subarray with exactly K Prime Numbers.… Read More »

## Count the elements having frequency equals to its value

Given an array of integers arr[] of size N, the task is to count all the elements of the array which have a frequency equals… Read More »