Skip to content

Category Archives: Algorithms

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 Quicksort… Read More
Given two binary strings that represent value of two integers, find the product of two strings. For example, if the first bit string is “1100”… Read More
Given two strings where first string may contain wild card characters and second string is a normal string. Write a function that returns true if… Read More