## Sum of natural numbers using recursion

Given a number n, find sum of first n natural numbers. To calculate the sum, we will use a recursive function recur_sum(). Examples : Input… Read More »

Given a number n, find sum of first n natural numbers. To calculate the sum, we will use a recursive function recur_sum(). Examples : Input… Read More »

Given an array, write functions to find minimum and maximum elements in it. Output: Minimum element of array: 1 Maximum element of array: 1234 Time… Read More »

We have discussed different methods of linked list insertion. How to recursively create a linked list? Recursively inserting at the end: To create a Linked… Read More »

Given a singly linked list delete node at k-th position without using loop. Examples: Input : list = 9->8->3->5->2->1 k = 4 Output : 9->8->3->2->1… Read More »

The Alexander Bogomolyn’s algorithm is used to permute first N natural numbers. Given the value of N we have to output all the permutations of… Read More »

Given an input string of numbers, find all combinations of numbers that can be formed using digits in the same order. Examples: Input : 123… Read More »

Given an area of N X M. You have infinite number of tiles of size 2i X 2i, where i = 0, 1, 2,… so… Read More »

Given a set of characters generate all possible passwords from them. This means we should generate all possible permutations of words using the given characters,… Read More »

Given a positive integer n, print all n-bit binary numbers having more 1’s than 0’s for any prefix of the number. Examples: Input : n… Read More »

Given a binary tree, we need to write a program to print all leaf nodes of the given binary tree from left to right. That… Read More »

Tower of Hanoi is a mathematical puzzle. Traditionally, It consists of three poles and a number of disks of different sizes which can slide onto… Read More »

m-th summation of first n natural numbers is defined as following. If m > 1 SUM(n, m) = SUM(SUM(n, m – 1), 1) Else SUM(n,… Read More »

Given a number n, we need to print all n-digit binary numbers with equal sum in left and right halves. If n is odd, then… Read More »

Given coordinates of a source point (x1, y1) determine if it is possible to reach the destination point (x2, y2). From any point (x, y)… Read More »

We are given a string S, we need to find count of all contiguous substrings starting and ending with same character. Examples : Input :… Read More »