# Category Archives: Algorithms

## Number of non-negative integral solutions of a + b + c = n

Given a number n, find number of ways we can add 3 non-negative integers so that their sum is n. Examples : Input : n… Read More »

## Minimum sum of two numbers formed from digits of an array

Given an array of digits (values are from 0 to 9), find the minimum possible sum of two numbers formed from digits of the array.… Read More »

## Longest Common Prefix using Divide and Conquer Algorithm

Given a set of strings, find the longest common prefix. Examples: Input : {“geeksforgeeks”, “geeks”, “geek”, “geezer”} Output : “gee” Input : {“apple”, “ape”, “april”}… Read More »

## How to find Lexicographically previous permutation?

Given a word, find lexicographically smaller permutation of it. For example, lexicographically smaller permutation of “4321” is “4312” and next smaller permutation of “4312” is… Read More »

## Minimax Algorithm in Game Theory | Set 2 (Introduction to Evaluation Function)

Prerequisite : Minimax Algorithm in Game Theory As seen in the above article, each leaf node had a value associated with it. We had stored… Read More »

## LCM of given array elements

Given an array of n numbers, find LCM of it. Input : {1, 2, 8, 3} Output : 24 Input : {2, 7, 3, 9,… Read More »

## Find number of subarrays with even sum

Given an array, find the number of subarrays whose sum is even. Example : Input : arr[] = {1, 2, 2, 3, 4, 1} Output… Read More »

## In-place replace multiple occurrences of a pattern

Given a string and a pattern, replace multiple occurrences of a pattern by character ‘X’. The conversion should be in-place and solution should replace multiple… Read More »

## Longest Common Increasing Subsequence (LCS + LIS)

Prerequisites : LCS, LIS Given two arrays, find length of the longest common increasing subsequence [LCIS] and print one of such sequences (multiple sequences may… Read More »

## Find paths from corner cell to middle cell in maze

Given a square maze containing positive numbers, find all paths from a corner cell (any of the extreme four corners) to the middle cell. We… Read More »

## A* Search Algorithm

Motivation To approximate the shortest path in real-life situations, like- in maps, games where there can be many hindrances. We can consider a 2D Grid… Read More »

## Number of ways to calculate a target number using only array elements

Given an integer array, find number of ways to calculate a target number using only array elements and addition or subtraction operator. Example: Input: arr[]… Read More »

## Linear Diophantine Equations

A Diophantine equation is a polynomial equation, usually in two or more unknowns, such that only the integral solutions are required. An Integral solution is… Read More »

## Maximum absolute difference between sum of two contiguous sub-arrays

Given an array of integers, find two non-overlapping contiguous sub-arrays such that the absolute difference between the sum of two sub-arrays is maximum. Example: Input:… Read More »

## Minimax Algorithm in Game Theory | Set 1 (Introduction)

Minimax is a kind of backtracking algorithm that is used in decision making and game theory to find the optimal move for a player, assuming… Read More »