Skip to content

Category Archives: Greedy

Given three integers A, B, and C, the task is to find the minimum possible value of |A – X| + |B – Y| +… Read More
Given a positive integer N and an array arr[] consisting of K integers and consider a binary string(say S) having N set bits, the task… Read More
Given an array arr[] consisting of N strings where each string consists of ‘(‘ and ‘)’, the task is to check if a Regular Bracket… Read More
Given an array arr[] consisting of N pairs of items as {value, weight}, the task is to find the maximum sum of profit by choosing… Read More
Given two strings str1 and str2 of same length N, the task is to check if there exists any permutation possible in any of the… Read More
Given an array arr, the task is to find the maximum sum of subsequence after flipping signs of at most K elements. Examples: Input: arr… Read More
Given an integer array arr[] of N integers, the task is to make each adjacent pair in the array co prime, by adding minimum number of… Read More
Given an array A[] consisting of N intervals and a target interval X, the task is to find the minimum number of intervals from the… Read More
Given an array arr of N integers, the task is to calculate the length of longest sequence of consecutive integers that can be formed from… Read More
Given an array arr of N integers, and an array of keys, such that key for each element in arr is equal to its index… Read More
Given two positive integers X and K, the task is to find the K-th smallest positive integer Y, such that X + Y = X… Read More
Given an array arr of length N with values 1 and 2 indicating type 1 and type 2 elements and two players, player1 and player2.… Read More
Given a range [L, R], the task is to find the count of numbers in the range [L, R] that can be expressed as a… Read More
Given a positive integer N, the task is to find the maximum number of unique squares that can be formed with N arbitrary points in… Read More
Given a string S consisting of N lowercase alphabets, the task is to modify the given string by replacing all the characters with characters other… Read More