# Sorting

### Maximum frequency of any array element possible by exactly K increments

#include using namespace std;  void findMostFrequent(int arr[], int N,                      int K){    int start = 0, end = 0;          sort(arr, arr + N);              int mostFreq =…

Read More

### Minimize sum of numbers required to convert an array into a permutation of first N natural numbers

Minimize sum of numbers required to convert an array into a permutation of first N natural numbersGiven an array A[] of…

Read More

### Probability of obtaining pairs from two arrays such that element from the first array is smaller than that of the second array

import java.util.*;  class GFG {                  static double probability(int[] arr1,                              int[] arr2)    {                int N = arr1.length;                  int M = arr2.length;                  double res = 0;                          Arrays.sort(arr2);                  for (int i =…

Read More

### Minimize sum of points assigned to distinct elements present in an array

Minimize sum of points assigned to distinct elements present in an arrayGiven an array arr[] of size N, the task…

Read More

### Split array into K subarrays such that sum of maximum of all subarrays is maximized

#include using namespace std;  void partitionIntoKSegments(int arr[],                            int N, int K){        if (N < K) {        cout

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

Read More

### Find the array element having minimum sum of absolute differences with all other array elements

Find the array element having minimum sum of absolute differences with all other array elementsGiven an array arr[] of size…

Read More

### Minimum sprinkers required to be turned on to water the plants

Given an array arr[] consisting of N integers, where the ith element represents the range of a sprinkler i.e [i-arr[i],…

Read More

### Minimum number of jumps required to sort numbers placed on a number line

#include using namespace std;void minJumps(int w[], int l[], int n){        if (n == 1) {        cout prevElementPos)            continue;                                while (currElementPos

### Check if removal of a subsequence of non-adjacent elements makes the array sorted

Check if removal of a subsequence of non-adjacent elements makes the array sortedGiven a binary array arr[] of size N,…

Read More