# Category Archives: Algorithm

## Variation in Nim Game

Prerequisites: Sprague Gruncy theorem Grundy Numbers Nim is a famous game in which two players take turns removing items from distinct piles. During each turn,… Read More »

## Sum of first n even numbers

Given a number n. The problem is to find the sum of first n even numbers. Examples: Input : n = 4 Output : 20… Read More »

## Sum of k-th group of odd positive numbers

The positive odd numbers in ascending order as 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, …. and grouped as (1), (3, 5),… Read More »

## Check if possible to cross the matrix with given power

Given a matrix of N X M, each cell consist of an integer. We have initial power of K and we are allowed to move… Read More »

## Sum of first n odd numbers in O(1) Complexity

Given the sequence of odd numbers 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, …. Find the sum of first n… Read More »

## Program to Convert Radian to Degree

Before moving to the actual solution, let’s try to find out what is a degree, a radian, and their relations. Radian : The radian is… Read More »

## Program to Convert Km/hr to miles/hr and vice versa

Given a speed in km/hr, Convert it to m/hr and m/hr to km/hr. Examples: Input : 150 (km/hr) Output : 93.21 Input : 100 (m/hr)… Read More »

## n-th term in series 2, 12, 36, 80, 150….

Given a series 2, 12, 36, 80, 150.. Find the n-th term of the series. Examples: Input : 2 Output : 12 Input : 4… Read More »

## K-Primes (Numbers with k prime factors) in a range

Given three integers A, B and K. We need to find no. of K-prime numbers in the range [A, B]. A number is called K-prime… Read More »

## Minimum cost to make Longest Common Subsequence of length k

Given two string X, Y and an integer k. Now the task is to convert string X with minimum cost such that the Longest Common… Read More »

## Largest divisible pairs subset

Given an array of n distinct elements, find length of the largest subset such that every pair in the subset is such that the larger… Read More »

## Game of replacing array elements

There are two players A and B who are interested in playing a game of numbers. In each move a player pick two distinct number,… Read More »

## Narayana number

In combinatorics, the Narayana numbers N(n, k), n = 1, 2, 3 …, 1 <= k <= n, form a triangular array of natural numbers,… Read More »

## Find largest element from array without using conditional operator

Given an array of n-elements, we have to find the largest element among them without using any conditional operator like greater than or less than.… Read More »

## Find trace of matrix formed by adding Row-major and Column-major order of same matrix

Given two integers N and M. Consider two matrix ANXM, BNXM. Both matrix A and matrix B contains elements from 1 to N*M. Matrix A… Read More »