# Category Archives: Algorithm

## Alternate sorting of Linked list

Given a linked list containing n nodes. The problem is to rearrange the nodes of the list in such a way that the data in… Read More »

## Minimum height of a triangle with given base and area

Given two integers a and b, find the smallest possible height such that a triangle of atleast area “a” and base “b” can be formed.… Read More »

## Calculate volume and surface area of a cone

Given slant height, height and radius of a cone, we have to calculate the volume and surface area of the cone. Cone : Cone is… Read More »

## Fermat’s little theorem

Fermat’s little theorem states that if p is a prime number, then for any integer a, the number a p – a is an integer… Read More »

## Product of maximum in first array and minimum in second

Given two arrays, the task is to calculate the product of max element of first array and min element of second array References : Asked… Read More »

## Queries for maximum difference between prime numbers in given ranges

Given n queries of the form range [L, R]. The task is to find the maximum difference between two prime numbers in the range for… Read More »

## Program to calculate distance between two points

You are given two co-ordinates (x1, y1) and (x2, y2) of a two dimensional graph. Find the distance between them. Examples: Input : x1, y1… Read More »

## Find x, y, z that satisfy 2/n = 1/x + 1/y + 1/z

Given n, find x, y, z such that x, y, z satisfy the equation “2/n = 1/x + 1/y + 1/z” There are multiple x,… Read More »

## Count all possible paths between two vertices

Count the total number of ways or paths that exist between two vertices in a directed graph. These paths doesn’t contain a cycle, the simple… Read More »

## Program to find area of a Trapezoid

Definition of Trapezoid : A Trapezoid is a convex quadrilateral with at least one pair of parallel sides. The parallel sides are called the bases… Read More »

## Sum of the series 1, 3, 6, 10… (Triangular Numbers)

Given n, no of elements in the series, find the summation of the series 1, 3, 6, 10….n. The series mainly represents triangular numbers. Examples:… Read More »

## Grouping Countries

People in a group, are sitting in a row numbered from 1 to n. Every has been asked the same question, “How many people of… Read More »

## Queries to print all divisors of number

Given a positive integer ‘n’ and query ‘q’. Print all the divisors of number ‘n’. Input: 6 Output: 1 2 3 6 Explanation Divisors of… Read More »

## Maximum sum path in a matrix from top to bottom

Consider a n*n matrix. Suppose each cell in the matrix has a value assigned. We can go from each cell in row i to a… Read More »

## Unset the last m bits

Given a non-negative number n. The problem is to unset the last m bits in the binary representation of n. Constraint: 1 <= m <=… Read More »