# Category Archives: Sorting

Insertion sort is an algorithm used to sort a collection of elements in ascending or descending order. The basic idea behind the algorithm is toâ€¦ Read More
We have discussed Pancake Sorting in the previous post. Following is a problem based on Pancake Sorting. Given an unsorted array, sort the given array. Youâ€¦ Read More
Given an unsorted array, sort the given array. You are allowed to do only following operation on array. flip(arr, i): Reverse array from 0 toâ€¦ Read More
Given an unsorted array, the task is to sort the given array. You are allowed to do only following operation on array.  flip(arr, i): Reverseâ€¦ Read More
Company : Qualcomm Position: Summer Intern(Software) Written Test It was an online MCQ test. Time limit was one hour. There were around 55 question. Itâ€¦ Read More
Given a linked list of 0s, 1s and 2s, The task is to sort and print it. Examples:  Input: 1 -> 1 -> 2 ->â€¦ Read More
Following is a typical recursive implementation of Quick Sort that uses last element as pivot.   C++ // CPP code for recursive function of Quicksort #includeâ€¦ Read More
Java // Java implementation of iterative quick sort import java.io.*; public class IterativeQuickSort {  void swap(int arr[], int i, int j)  {   int t =â€¦ Read More
C // An iterative implementation of quick sort #include <stdio.h>   // A utility function to swap two elements void swap(int* a, int* b) {â€¦ Read More
Given N machines. Each machine contains some numbers in sorted form. But the amount of numbers, each machine has is not fixed. Output the numbersâ€¦ Read More
Given a number, find the next smallest palindrome larger than this number. For example, if the input number is “2 3 5 4 5”, theâ€¦ Read More
Given an array of N elements, where each element is at most K away from its target position, devise an algorithm that sorts in O(Nâ€¦ Read More
Given an array of integers, find anyone combination of four elements in the array whose sum is equal to a given value X. For example, â€¦ Read More
Given an unsorted array and a number n, find if there exists a pair of elements in the array whose difference is n. Examples:  Input: arr[]â€¦ Read More
Given an array and a value, find if there is a triplet in array whose sum is equal to the given value. If there isâ€¦ Read More