# Greedy

### Minimum operations required to reduce N to 0 by either replacing N with N/M or incrementing M by 1

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

### 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…

### Minimum number of deques required to make the array sorted

#include using namespace std;int minDeques(vector arr){            vector fronts, backs;        for (int i = 0; i < arr.size(); i++) {                        bool hasBeenPushed = false;        for…

### 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…