# Category Archives: Algorithms

Given a linked list, apply the Quick sort algorithm to sort the linked list. The important things about implementation are, that it changes pointers rather… Read More
Given three strings A, B and C. Write a function that checks whether C is an interleaving of A and B. C is said to… Read More
Given a function ‘int f(unsigned int x)’ which takes a non-negative integer ‘x’ as input and returns an integer as output. The function is monotonically… Read More
Given an input string and a dictionary of words, find out if the input string can be segmented into a space-separated sequence of dictionary words.… Read More
Given n numbers, each with some frequency of occurrence. Return a random number with probability proportional to its frequency of occurrence. Example:  Let following be… Read More
Consider a row of n coins of values v1 . . . vn, where n is even. We play a game against an opponent by… Read More
Given an array of size n and an integer k, find all elements in the array that appear more than n/k times.  Examples: Input: arr[]… Read More
Given an array of size n, generate and print all possible combinations of r elements in array. For example, if input array is {1,… Read More
Evaluate an expression represented by a String. The expression can contain parentheses, you can assume parentheses are well-matched. For simplicity, you can assume only binary… Read More
Given n dice each with m faces, numbered from 1 to m, find the number of ways to get sum X. X is the summation… Read More
Given an array arr[] of integers. Find a peak element i.e. an element that is not smaller than its neighbors.  Note: For corner elements, we… Read More
Given an array of integers, sort the array according to frequency of elements. For example, if the input array is {2, 3, 2, 4, 5,… Read More
Given two strings ‘X’ and ‘Y’, find the length of the longest common substring.  Examples :  Input : X = “GeeksforGeeks”, y = “GeeksQuiz” Output :… Read More
Given string str, the task is to find the minimum number of characters to be inserted to convert it to a palindrome. Before we go… Read More
Following is a typical recursive implementation of QuickSort for arrays. The implementation uses last element as pivot.    C++ /* A typical recursive implementation of… Read More