# array-rearrange

### Modify array to a permutation of consecutive numbers of longest length by at most K insertions

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

### Rearrange the Array by shifting middle elements to start and end alternatively

Given an array, the task is to shift the middle element to the start and end of the array alternatively,…

### Rearrange Array to find K using Binary Search algorithm without sorting

#include using namespace std;  void Rearrange(int arr[], int K, int N){        int ans[N + 1];              int f = -1;      for (int i = 0;…

### Maximize the smallest array element by incrementing all elements in a K-length subarray by 1 exactly M times

Given an array arr[] of size N, and integers M and K, the task is to find the maximum possible…

### Minimize moves required to make array elements equal by incrementing and decrementing pairs | Set 2

Given an array arr[] of size N, the task is to print the minimum number of moves required to make…

### Maximize average of the ratios of N pairs by M increments

#include using namespace std;  double change(int pass, int total){    double currentPassRatio, newPassRatio;    double increase;          currentPassRatio = ((double)pass)                       / total;          newPassRatio = ((double)(pass + 1))                   / (total +…

### Sort a permutation of first N Natural Numbers by swapping pairs satisfying given conditions

def Swap(x, y, p, posOfCurrNum):         posOfCurrNum[p[x]], posOfCurrNum[p[y]] = posOfCurrNum[p[y]], posOfCurrNum[p[x]]    p[x], p[y] = p[y], p[x]    return p, posOfCurrNumdef sortArray(p, n):                 posOfCurrNum =  *…

### Minimum replacements required to make sum of all K-length subarrays equal

Given an array arr[] consisting of N positive integers and an integer K, the task is to make the sum…