# Category Archives: Greedy

## Find smallest number K such that K % p = 0 and q % K = 0

Given two integers p and q, the task is to find the smallest number K such that K % p = 0 and q %… Read More »

## Minimum LCM and GCD possible among all possible sub-arrays

Given an array arr[] of N positive integers, the task is to find the minimum LCM and GCD between elements of all possible sub-array. Examples:… Read More »

## Minimum operations to make frequency of all characters equal K

Given a string S of length N. The task is to find the minimum number of steps required on strings, so that it has exactly… Read More »

## Count possible moves in the given direction in a grid

Given a grid N x M size and initial position (X, Y) and a series of K moves. Each move contains 2 integers Dx and… Read More »

## Select numbers in such way to maximize the amount of money

Given two arrays A1 and A2 of N numbers. There are two people A and B who select numbers out of N. If A selects… Read More »

## Minimum number of elements that should be removed to make the array good

Given an array arr[], the task is to find the minimum number of elements that must be removed to make the array good. A sequence… Read More »

## Shortest path to traverse all the elements of a circular array in increasing order

There are N distinct integers arranged on a circle. The distance between any two adjacent numbers is 1. The task is to travel on this… Read More »

## Minimum elements to be removed such that sum of adjacent elements is always odd

Given an array of N integers. The task is to eliminate the minimum number of elements such that in the resulting array the sum of… Read More »

## Count all possible N digit numbers that satisfy the given condition

Given an integer N, the task is to count all possible N digit numbers such that A + reverse(A) = 10N – 1 where A… Read More »

## Maximum sub-array sum after dividing array into sub-arrays based on the given queries

Given an array arr[] and an integer k, we can cut this array at k different positions where k[] stores the positions of all the… Read More »

## Find Intersection of all Intervals

Given N intervals of the form of [l, r], the task is to find the intersection of all the intervals. An intersection is an interval… Read More »

## Choose points from two ranges such that no point lies in both the ranges

Given two segments [L1, R1] and [L2, R2], the task is to choose two elements x and y from both the ranges (one from range… Read More »

## Maximum size of sub-array that satisfies the given condition

Given an array arr[] of integers. The task is to return the length of the maximum size sub-array such that either one of the condition… Read More »

## Maximum count of sub-strings of length K consisting of same characters

Given a string str and an integer k. The task is to count the occurrences of sub-strings of length k that consist of the same… Read More »

## Maximum number of teams that can be formed with given persons

Given two integers N and M which denote the number of persons of Type1 and Type2 respectively. The task is to find the maximum number… Read More »