# Category Archives: Algorithms

## Number of ways to select exactly K even numbers from given Array

Given an array arr[] of n integers and an integer K, the task is to find the number of ways to select exactly K even… Read More »

## Subtraction of two large numbers using 9’s compliment

Given two strings str1 and str2 of given lengths N and M respectively, each representing a large number, the task is to subtract one from… Read More »

## Maximum possible GCD for a pair of integers with product N

Given an integer N, the task is to find the maximum possible GCD among all pair of integers with product N.Examples:   Input: N=12 Output: 2 Explanation: All possible… Read More »

## Find M such that GCD of M and given number N is maximum

Given an integer N greater than 2, the task is to find an element M such that GCD(N, M) is maximum. Examples: Input: N =… Read More »

## Count of Missing Numbers in a sorted array

Given a sorted array arr[], the task is to calculate the number of missing numbers between the first and last element of the sorted array.… Read More »

## Construct a matrix with sum equal to the sum of diagonal elements

Given an integer N, the task is to construct a matrix of size N2 using positive and negative integers and excluding 0, such that the… Read More »

## 3 Different ways to print Fibonacci series in Java

Given a number N, we need to find the Fibonacci Series up to the N term. The Fibonacci series is a series of elements where,… Read More »

## Content of a Polynomial

Given an array arr[] which denotes the integer coefficients of the polynomial, the task is to find the content of polynomial.  Content of polynomials with… Read More »

## Find two numbers with given sum and maximum possible LCM

Given an integer X, the task is to find two integers A and B such that sum of these two numbers is X and the… Read More »

## Sort an array of strings based on count of distinct characters

Given a string array arr[] as input, the task is to print the words sorted by number of distinct characters that occur in the word,… Read More »

## Maximize count of set bits in a root to leaf path in a binary tree

Given a binary tree, the task is to find the total count of set bits in the node values of all the root to leaf… Read More »

## Queries to find sum of distance of a given node to every leaf node in a Weighted Tree

Given a Undirected Weighted Tree having N nodes and E edges. Given Q queries, with each query indicating a starting node. The task is to… Read More »

## Queries to update each element in subarray to Bitwise XOR with a given value

Given an array arr[], and queries Q[][] of the form (l, r, val), the task for each query is to update all the elements in… Read More »

## Minimum Cost Path in a directed graph via given set of intermediate nodes

Given a weighted, directed graph G, an array V[] consisting of vertices, the task is to find the Minimum Cost Path passing through all the… Read More »

## Maximum of minimum difference of all pairs from subsequences of given size

Given an integer array A[ ] of size N, the task is to find a subsequence of size B such that the minimum difference between… Read More »