Given two integers N and M, the task is to calculate the minimum number of operations required to reduce N…

# Greedy

### Length of longest subsequence such that prefix sum at every element remains greater than zero

Given an array arr[] of size N and an integer X, the task is to find the length of the…

### Check if any row of the matrix can be converted to the elements present in the target row

import java.util.*; class GFG { public static boolean checkPossibleOrNot( int[][] mat, int[] target) { int[] comp = new int[mat[0].length]; Arrays.fill(comp, Integer.MIN_VALUE); for (int[] val : mat) { if…

### Minimum adjacent swaps required to get Kth smallest number greater than given number

#include using namespace std; void minSwapsKthLargest(string str, int k){ string res = str; for (int i = 0; i < k; i++) { next_permutation( str.begin(),…

### Maximum length of subarray with same sum at corresponding indices from two Arrays

Given two arrays A[] and B[] both consisting of N integers, the task is to find the maximum length of…

### Maximum length of consecutive 1s or 0s after flipping at most K characters

#include using namespace std; int maxLength(string str, int n, char c, int k){ int ans = -1; int cnt = 0; int left = 0; for…

### Largest value of K that a set of all possible subset-sum values of given Array contains numbers [0, K]

Given an array arr[] of N integers, the task is to find the maximum count of K, i.e, consecutive integers…

### Lexicographically largest permutation by sequentially inserting Array elements at ends

Given an array arr[] of N integers, the task is to find the lexicographically largest permutation by sequentially inserting the…

### Maximize sum of ratios of N given fractions by incrementing numerator and denominators K times by 1

#include using namespace std; double maxAverageRatio( vector& arr, int K){ int N = arr.size(); priority_queue q; for (int i = 0; i < N; i++)…