# Greedy

### Minimum operations to convert Binary Matrix A to B by flipping submatrix of size K

#include using namespace std;  int minMoves(vector a,             vector b,             int K){        int n = a.size(), m = a.size();            int cntOperations = 0;          for (int i =…

### Maximize the String value by assigning values in range [1, 26] to each character

Given a string S of size N, the task is to find the maximum sum of values assigned to all…

### Maximum cost of a value over the range [1, N] such that values lies in at most K given ranges

#include using namespace std;  void maxTotalCost(vector& arr,                  int M, int N, int K){        int totMaxSum = 0;      for (int i = 1; i

### Find permutation of numbers upto N with a specific sum in a specific range

#include using namespace std;  bool possible(int x, int S, int N){              int minSum = (x * (x + 1)) / 2;              int maxSum…

### Minimum jumps required to reach all array elements using largest element

#include using namespace std;#define ar array  ar expand(int idx, vector& A){                  int l = idx – 1;    int r = idx + 1;              while…

### Sum of the shortest distance between all 0s to 1 in given binary string

#include using namespace std;void findTotalDistance(string S, int N){            vector prefixDistance(N);    vector suffixDistance(N);            int cnt = 0;        bool haveOne = false;    for (int i = 0;…

### Minimize value of |A – X| + |B – Y| + |C – Z| such that X * Y = Z

Given three integers A, B, and C, the task is to find the minimum possible value of |A – X|…

### Minimum number of coins needed to remove all the elements of the array based on given rules

Given an array arr of length N with values 1 and 2 indicating type 1 and type 2 elements and…