Given an integer N, the task is to print the ways to get the sum N by repeatedly throwing a dice. Input: N = 3Output: 1… Read More

# Category Archives: Backtracking

Given 2 integers M and N, the task is to find the count of all the possible paths from top left to the bottom right… Read More

Given a root of binary tree and two integers startValue and destValue denoting the starting and ending node respectively. The task is to find the… Read More

Given a 2D matrix of size n*m, a source ‘s’ and a destination ‘d’, print the count of all unique paths from given ‘s’ to… Read More

Given a 2-D array mat[][], a source ‘s’ and a destination ‘d’, print all unique paths from given ‘s’ to ‘d’. From each cell, you… Read More

Given a matrix mat[][], and the coordinates of source and destination node, the task is to find the length of the longest path from source… Read More

Given an array of integers arr[], find the subsequence with maximum sum whose elements are first decreasing, then increasing, or vice versa, The subsequence can… Read More

Given vector nums, the task is to print all the possible permutations of the given vector using backtracking Examples: Input: nums[] = {1, 2, 3}Output:… Read More

Given a matrix mat[][] and an integer K, the task is to find the length of the shortest path in a matrix from top-left to… Read More

Given an array arr[] with N non-negative integers, find the maximum number of elements that are the same non-negative powers of their indices. arr[i] =… Read More

Find the number of permutations of first N positive integers such that the sum of any two consecutive numbers is prime where all the cyclic… Read More

Given an integer N, the task is to print all the unique combinations of putting N pieces in an NxN board. Note: Print (“*”) for… Read More

Given a positive integer N, the task is to print all possible sum of perfect squares such that the total sum of all perfect squares… Read More

A permutation also called an “arrangement number” or “order,” is a rearrangement of the elements of an ordered list S into a one-to-one correspondence with… Read More

Given string str containing characters ‘?’, ‘(‘ and ‘)’, the task is to replace the ‘?’ character with ‘(‘ or ‘)’ and print all the… Read More