# Category Archives: Sorting

## Maximize the sum of arr[i]*iOctober 15, 2017

Given an array of N integers. You are allowed to rearrange the element of the array. The task is to find the maximum value of… Read More »

## Pairs with Difference less than KOctober 14, 2017

Given an array of n integers, We need to find all pairs with difference less than k Examples: Input : a[] = {1, 10, 4,… Read More »

## Sort a Rotated Sorted ArrayOctober 11, 2017

You are given a rotated sorted array and your aim is to restore its original sort in place. Expected to use O(1) extra space and… Read More »

## Circle SortOctober 10, 2017

Circle sort algorithm can be visualized by drawing concentric circles on an array of integers. The elements of the array lying on the same circle… Read More »

## Stable Selection SortOctober 4, 2017

A sorting algorithm is said to be stable if two objects with equal or same keys appear in the same order in sorted output as… Read More »

## Minimum product pair an array of positive IntegersSeptember 29, 2017

Given an array of positive integers. We are required to write a program to print the minimum product of any two numbers of the given… Read More »

## Sort string of characters

Given a string of lowercase characters from ‘a’ – ‘z’. We need to write a program to print the characters of this string in sorted… Read More »

## Difference between highest and least frequencies in an array

Given an array, find the difference between highest occurrence and least occurrence of any number in an array Examples: Input : arr[] = [7, 8,… Read More »

## Count points covered by given intervals

Consider an infinite x-y plane. Infinite people walk on the plane in upward or +ve Y direction. At each integer point on the x-axis, only… Read More »

## Sort a binary array using one traversalSeptember 26, 2017

Given a binary array, sort it using one traversal and no extra space. Examples: Input : 1 0 0 1 0 1 0 1 1… Read More »

## Check if given array is almost sorted (elements are at-most one position away)September 21, 2017

Given an array with n distinct elements. An array is said to be almost sorted (non-decreasing) if any of its elements can occurs maximum of… Read More »

## Maximum area rectangle by picking four sides from arraySeptember 20, 2017

Given an array of n positive integers that represent lengths. Find out the maximum possible area whose four sides are picked from given array. Note… Read More »

## Sort elements by frequency | Set 4 (Efficient approach using hash)

Print the elements of an array in the decreasing frequency if 2 numbers have same frequency then print the one which came first. Examples: Input… Read More »

## Dual pivot QuicksortSeptember 19, 2017

As we know, the single pivot quick sort takes a pivot from one of the ends of the array and partitioning the array, so that… Read More »

## How to make Mergesort to perform O(n) comparisons in best case?September 17, 2017

As we know, Mergesort is a divide and conquer algorithm that splits the array to halves recursively until it reaches an array of the size… Read More »