# An algorithm to move all zeros to rightmost in an integer array.

Given an integer array, which contains some ‘k’ zeros. We aim to move all ‘k’ zeros to the right of most of the integer array. Let us see this with an example. Algorithm Iterate through each integer in the array and take a variable “pos,” representing the end of the array at first. If theRead More »

# Find if there exists a pair with a given sum in a sorted array.

Given an array of integers which are in ascending order and a sum. Our aim is to find if there is any pair of integers which total is equal to input sum. Let us discuss this problem with below example. Above example contains numbers 4 & 9 which sum is equal to our input. WeRead More »

# Find all possible combinations of decodings of a number.

Given an encoding number as explained below, we aim to print all combinations of decoding strings to that input number. The encoding number is as follows. Defining a recursion for this problem is very simple. Let us see the recursion tree for the input number. Let us now write the code for this recursion algorithm.Read More »

# Remove alternate duplicate characters in a sentence in-place.

Given a string of characters, we aim to remove all its alternate duplicate characters in that string in-place. Let us see this with an example. We can solve this using an additional integer array of constant size of 127. Algorithm steps are as follows. For every character in the string, we insert ‘1’ in itsRead More »

# Longest palindromic substring length of a given string (recursion and dynamic programming approach)

A substring is a string formed based on a continuous subset of characters of another big series. Let’s see the following example. As we do in the longest palindromic subsequence length, we have a similar formula here with a small condition. The condition here is the length of substring whichever formed should be equal toRead More »

# 0/1 Knapsack problem example with recursion and dynamic programming solutions

A farmer wants to sell his farm products in the city. He has a knapsack with the capacity of “N” kgs weight, and he has products with more than ‘N’ kgs weight. He wants to fill his backpack in such a way that he gets more money after selling the products in the knapsack. HereRead More »

# Activity selection(Interval scheduling maximization) problem greedy approach

Given a set of activities (tasks) with its start time and end times. We aim to find all non-overlapping activities in the given interval. Let’s understand the problem with the following example. This scheduling problem can be solved using the greedy approach, to solve this we first need to sort all activities based on theirRead More »

# Coin change problem (Find all number of combinations that formed a sum amount with given denominations)

Given a set of denominations of coins and an amount, our aim is find number of combinations in which we can arrange denominations to form our input amount. Let’s understand this better with following example. We can solve this problem using below two different approaches. Recursion Dynamic Programming. Recursion Let’s divide our problem into smallerRead More »