# Category Archives: Algorithm

## Number of subsequences as “ab” in a string repeated K times

Given a String S, consider a new string formed by repeating the S exactly K times. We need find the number of subsequences as “ab”… Read More »

## Dividing an array into two halves of same sum

Given an even size array of integers. We need to find if it is possible to divide array elements into two sets such that following… Read More »

## Given a large number, check if a subsequence of digits is divisible by 8

Given a number of at most 100 digits. We have to check if it is possible, after removing certain digits, to obtain a number of… Read More »

## Find all possible coordinates of parallelogram

Find the all the possible coordinate from the given three coordinates to make a parallelogram of a non-zero area. Let’s call A,B,C are the three… Read More »

## Largest number less than or equal to N in BST (Iterative Approach)

We have a binary search tree and a number N. Our task is to find the greatest number in the binary search tree that is… Read More »

## Total no of 1’s in numbers

Given an integer n, count the total number of digit 1 appearing in all positive integers less than or equal to n. Examples: Input :… Read More »

## GCD of elements in a given range

Given two numbers n and m. Find the biggest integer a(gcd), such that all integers n, n + 1, n + 2, …, m are… Read More »

## Ways to paint stairs with two colors such that two adjacent are not yellow

Given n stairs and we have 2 colour yellow and green the task is that we have to paint given stairs by given colour with… Read More »

## Maximum integral co-ordinates with non-integer distances

Given a maximum limit of x – coordinate and y – coordinate, we want to calculate a set of coordinates such that the distance between… Read More »

## Generate a pythagoras triplet from a single integer

Given a single integer n [1, 1000000000], generate a pythagoras triplet with includes n as of it’s sides if possible. Examples: Input : 22 Output… Read More »

## Largest number with prime digits

Given a huge integer value n, find the largest integer value x such that x

## Find if given number is sum of first n natural numbers

Given a number s (1 n, r = mid – 1. e) Else sum < n, l = mid + 1. 3- Return -1, if… Read More »

## Smallest root of the equation x^2 + s(x)*x – n = 0, where s(x) is the sum of digits of root x.

You are given an integer n, find the smallest positive integer root of equation x, or else print -1 if no roots are found. Equation:… Read More »

## Exponential Squaring (Fast Modulo Multiplication)

Given two numbers base and exp, we need to compute baseexp under Modulo 10^9+7 Examples: Input : base = 2, exp = 2 Output :… Read More »

## Divisors of n-square that are not divisors of n

Given an positive large integer n. Count the number of positive divisors of n2 which are not divisible by any divisor of n(1