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

# array-rearrange

### 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 = [0] *…

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

### Rearrange an array to maximize sum of Bitwise AND of same-indexed elements with another array

#include using namespace std;int maximizeAnd(int i, int mask, int* A, int* B, int N, vector& dp){ if (i == N) return 0; if (dp[i][mask] !=…

### Minimize sum of product of same-indexed elements of two arrays by reversing a subarray of one of the two arrays

import java.io.*;import java.util.*; public class Main { static void minimumProdArray(long a[], long b[], int l) { long total = 0; for (int i = 0; i…