Consider a rat placed at (0, 0) in a square matrix m[ ][ ] of order n and has to reach the destination at (n-1,… Read More

# Category Archives: Backtracking

Given a string, generate all permutations of it that do not contain ‘B’ after ‘A’, i.e., the string should not contain “AB” as a substring.… Read More

Travelling Salesman Problem (TSP): Given a set of cities and distance between every pair of cities, the problem is to find the shortest possible route… Read More

Given a Tree with N nodes, the task is to find a triplet of nodes (a, b, c) such that the number of nodes covered… Read More

Given a number N which is the total number of nodes in a complete binary tree where nodes are number from 1 to N sequentially… Read More

Given a positive integer number N. The task is to generate all the binary strings of N bits. These binary strings should be in ascending… Read More

Given a string str, the task is to print all the distinct permutations of str. A permutation is an arrangement of all or part of… Read More

Given a keypad of a mobile, and keys that need to be pressed, the task is to print all the words which are possible to… Read More

Given a grid grid[][] with 4 types of blocks: 1 represents the starting block. There is exactly one starting block. 2 represents the ending block.… Read More

Given a string str, the task is to print all the permutations of str. A permutation is an arrangement of all or part of a… Read More

Given integers M, N and K, the task is to place K knights on an M*N chessboard such that they don’t attack each other. The… Read More

Given a string, find minimum no of swaps(not necessarily adjacent) to convert it into a string which have similar characters side by side. Examples: Input… Read More

Given a binary matrix. The task is to flip the matrix horizontally(find the image of the matrix), then invert it. Note: To flip a matrix… Read More

Given integers N, P and Q where N denotes the destination position. The task is to move from position 0 to position N with minimum… Read More