Category: Sorting

Sort an array using one swap

Given an array where all its elements are sorted except two elements which were swapped, sort the array in linear time. Assume there are no duplicates in the array.

Get the surpasser count for each element of an array

Given an array of integers having distinct elements, find the surpasser count for each element in it. In other words, for each element of the array, find the number of elements to its right which are greater than it.