# Category Archives: Algorithm

## 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 »

## Happy Numbers

A Happy Number n is defined by the following process. Starting with n, replace it with the sum of the squares of its digits, and… Read More »

## N expressed as sum of 4 prime numbers

Express a given number as a summation of 4 positive primes. If it is not possible to express then print “-1”. Examples: Input: 24 Output:… Read More »

## Find intersection point of lines inside a section

Given N lines in two-dimensional space in y = mx + b form and a vertical section. We need to find out whether there is… Read More »

## Longest Repeated Subsequence

iven a string, print the longest repeating subseequence such that the two subsequence don’t have same string character at same position, i.e., any i’th character… Read More »

## Program to find Sum of a Series a^1/1! + a^2/2! + a^3/3! + a^4/4! +…….+ a^n/n!October 9, 2017

Given two values ‘a’ and ‘n’, find sum of series a^1/1! + a^2/2! + a^3/3! + a^4/4! +…….+ a^n/n!. Input : a = 2 and… Read More »

## Sub-tree with minimum color difference in a 2-coloured tree

A tree with N nodes and N-1 edges is given with 2 different colours for its nodes. Find the sub-tree with minimum colour difference i.e.… Read More »

## Policemen catch thieves

Given an array of size n that has the following specifications: Each element in the array contains either a policeman or a thief. Each policeman… Read More »

## Check whether a number has exactly three distinct factors or not

Given a positive integer n(1 <= n <= 1018). Check whether a number has exactly three distinct factors or not. Print “Yes” if it has… Read More »

## Series with largest GCD and sum equals to n

Given an integer n, print m increasing numbers such that the sum of m numbers is equal to n and the GCD of m numbers… Read More »

## Generate all passwords from given character set

Given a set of characters generate all possible passwords from them. This means we should generate all possible permutations of words using the given characters,… Read More »

## Number of compositions of a natural numberOctober 8, 2017

Given a natural number n, find the number of ways in which n can be expressed as a sum of natural numbers when order is… Read More »

## Count ways of choosing a pair with maximum difference

Given an array of n integers, we need to find the no. of ways of choosing pairs with maximum difference. Examples: Input : a[] =… Read More »

## Longest alternating sub-array starting from every index in a Binary Array

Given an array containing only 0s and 1s. For each index ‘i‘(0 index), find length of the longest alternating sub-array starting from ‘i‘ to ‘j‘… Read More »

## Minimum rotations to unlock a circular lock

You are given a lock which is made up of n-different circular rings and each ring has 0-9 digit printed serially on it. Initially all… Read More »