Arrange first N natural numbers such that absolute difference between all adjacent elements > 1

Given an integer N. The task is to find the permutation of first N natural numbers such that the absolute difference between any two consecutive… Read More »

Count operations of the given type required to reduce N to 0

Given an integer n. The task is to count the number of operations required to reduce n to 0. In every operation, n can be… Read More »

Maximum GCD from Given Product of Unknowns

Given two integers N and P where P is the product of N unknown integers, the task is to find the GCD of those integers.… Read More »

Program to find LCM of two Fibonnaci Numbers

Given here are two positive numbers a and b. The task is to print the least common multiple of a’th and b’th Fibonacci Numbers. The… Read More »

Array element with minimum sum of absolute differences

Given an array arr[] of N integers, the task is to find an element x from the array such that |arr[0] – x| + |arr[1]… Read More »

Count all Prime Length Palindromic Substrings

Given a string str, the task is to count all the sub-strings of str which are palindromes and their length is prime. Examples: Input: str… Read More »

Unique paths covering every non-obstacle block exactly once in a grid

Given a grid grid[][] with 4 types of blocks: 1 represents the starting block. There is exactly one starting block. 2 represents the ending block.… Read More »

Number of unique pairs in an array

Given an array of N elements, the task is to find all the unique pairs that can be formed using the elements of a given… Read More »

Make Binary Search Tree

Given an array arr[] of size N. The task is to find whether it is possible to make Binary Search Tree with the given array… Read More »

Minimum positive integer divisible by C and is not in range [A, B]

Given three positive integers A, B and C. The task is to find the minimum integer X > 0 such that: X % C =… Read More »

Check whether XOR of all numbers in a given range is even or odd

Given a range [ L, R ], the task is to find if value of XOR of all natural numbers in range L to R… Read More »

Print the last k nodes of the linked list in reverse order

Given a linked list containing N nodes and a positive integer k should be less than or equal to N. The task is to print… Read More »

Clone an undirected graph with multiple connected components

Given an undirected graph with multiple connected components, the task is to clone the graph. Cloning a graph with a single connected component can be… Read More »

Count number of trailing zeros in (1^1)*(2^2)*(3^3)*(4^4)*..

Given an integer n, the task is to find the number of trailing zeros in the function i.e. f(n) = 11 * 22 * 33… Read More »

Largest sphere that can be inscribed in a right circular cylinder inscribed in a frustum

Given here is a frustum of height h, top-radius r & base-radius R, which inscribes a right circular cylinder which in turn inscribes a sphere… Read More »