## Text Justification Problem

Objective: Given a list of words and length L. Format the words so that each line will have only L characters and fully justified (left and right justified). Restrictions- You need to fit as many...

Objective: Given a list of words and length L. Format the words so that each line will have only L characters and fully justified (left and right justified). Restrictions- You need to fit as many...

Objective: Given an array of integers of size 2n, write an algorithm to arrange them such that first n elements and last n elements are set up in alternative manner. Say n = 3 and...

Objective: Given an array of integer write an algorithm to find the local minima. Local Minima: An element is considered as local minima if it is less than both of its neighbors (if neighbors exist)....

Objective: The maximum subarray problem is the task of finding the contiguous subarray within a one-dimensional array of numbers which has the largest sum. Example: int [] A = {−2, 1, −3, 4, −1, 2, 1, −5, 4}; Output:...

Objective: Given an array A[], write an algorithm to find Maximum difference between two elements where larger element appears after the smaller element or in other words find A[i] and A[j] such that A[j]-A[i]...

Objective: Given two dimensional matrix, write an algorithm to count all possible paths from top left corner to bottom-right corner. You are allowed to move only in two directions, move right OR move down....

Objective: Given a linked list write an algorithm to swap nodes in pairs by changing links . Earlier we have seen “Swap Every Kth node in a Linked List“, where we have seen how...

Objective: Given a binary search tree (BST), convert it into greater sum tree. What is greater sum tree: Greater sum tree is a tree in which every node contains the sum of all the...

Objective: Given a linked list and integer ‘k’, write an algorithm to reverse the linked list in groups of size ‘k’. Example: Approach: Earlier we have seen how to reverse a linked list, solution...

Objective: Given a binary tree, find the sum of all the nodes which are left as well as leaves nodes. Example: Approach: Approach is quite simple. Do the inorder traversal check if...

Objective: Given a binary tree, write an algorithm to convert it into its Sum tree. What is Sum tree: Sum tree of a binary tree, is a tree where each node in the converted...

Objective: Given a binary tree, write an algorithm to delete it. This is one of the basic problem in trees. if you are new to trees then this problem will help you build your...

Objective: Given a binary tree and a given number x, Write an recursive algorithm to search the element in the tree. This is one of the very basic problems of tree. If you are...

There are multiple ways to in which you can traverse a tree. In this article we will see these traversals in detail. If you are new to trees then I would recommend that you...

Objective: Given a rope of length n meters, write an algorithm to cut the rope in such a way that product of different lengths of rope is maximum. At least one cut has to...

Objective: Given two string sequences, write an algorithm to find the length of longest subsequence present in both of them. These kind of dynamic programming questions are very famous in the interviews like Amazon,...

Objective: Given a rod of length n inches and a table of prices pi, i=1,2,…,n, write an algorithm to find the maximum revenue rn obtainable by cutting up the rod and selling the pieces....

Objective: Given a set of coins and amount, Write an algorithm to find out how many ways we can make the change of the amount using the coins given. This is another problem in...

Objective: Print All N Length Strings from Given String of Length K where characters can appear multiple time. Example: String k = “ALGO” N=2 Result: AA LA GA OA AL LL GL OL AG...

Objective: Generate Well Ordered Passwords of a Given Length K. Well ordered means that digits should be in increasing order in every generated password. Example: K = 7 1234567 1234568 1234569 1234578 1234579 1234589...

Objective: Given Number K, Print all the strings of N length. Example: N = 2, K = 3 [1, 1] [2, 1] [3, 1] [1, 2] [2, 2] [3, 2] [1, 3] [2, 3]...

Objective: Given a number N, Write an algorithm to print all possible subsets with Sum equal to N In this problem you will see the power of recursion. This question has been asked in...

Objective: Given a set of positive integers, and a value sum S, find out if there exist a subset in array whose sum is equal to given sum S. Example: int[] A = {...

Objective : Given an string and a dictionary of words, find out if the input string can be broken into a space-separated sequence of one or more dictionary words. Example: dictionary = [“I” ,...

Objective : A knight’s tour is a sequence of moves of a knight on a chessboard such that the knight visits every square only once. If the knight ends on a square that is...

Objective : Given a 2D matrix of characters. Check whether the word exist in the matrix or not. If it exists then print its path. All movements are allowed (right, left, up, down and...

Objective : In chess, a queen can move as far as she pleases, horizontally, vertically, or diagonally. A chess board has 8 rows and 8 columns. The standard 8 by 8 Queen’s problem asks...

Given a maze, NxN matrix. A rat has to find a path from source to destination. maze[0][0] (left top corner)is the source and maze[N-1][N-1](right bottom corner) is destination. There are few cells which are...

SUDOKU Puzzle : The objective is to fill a 9×9 grid with digits so that each column, each row, and each of the nine 3×3 sub-grids that compose the grid (also called “boxes”, “blocks”,...

What is Backtracking Programming?? Recursion is the key in backtracking programming. As the name suggests we backtrack to find the solution. We start with one possible move out of many available moves and try...

Objective: A child is climbing up a staircase with n steps, and can hop either 1 step, 2 steps, or 3 steps at a time. Implement a method to count how many possible ways...

Objective: Given a amount ‘A’ and n coins, v1<v2<v3<………..<vn . Write a program to find out minimum numbers of coins required to make the change for the amount ‘A’. Example: Amount: 5 Coins []...

What is Dynamic Programming: Dynamic programming is a technique to solve the recursive problems in more efficient manner. Many times in recursion we solve the sub-problems repeatedly. In dynamic programming we store the solution...

Objective: – Given a binary tree, Find the deepest left node in it. Approach: This approach is very similar to “Find the Deepest Node in a Binary Tree” with little modification. Take two global...

Objective: – Given a binary tree , Find the max element in it. Example: Approach: Use Recursion. Max will the Max(root, max element in left subtree, max element in rightsubtree) Recursively solve for max...

Objective: – Given a binary tree with three pointers left, right and nextSibling). Write the program to provide the nextsibling pointers. Example: Approach:

Objective: – Given two binary trees check if they are mirror image of each other. Example: Approach:

Objective: – Given a binary tree and X, Print all the paths starting from root so that sum of all the nodes in path equals to a given number. Example:

Objective: – Given a binary tree, find the diameter of it. What is Diameter Of a Tree: Diameter of tree is defined as A longest path or route between any two nodes in a...

Objective: – Given a binary tree, Find the deepest node in it. Approach: Take two global variable as “deepestlevel” and “value“. starting with level=0, Do the inorder traversal and whenever you go down one...

Objective: – Find the Height of a tree without Recursion. In our earlier post “Height of tree” we had used recursion to find it. In this post we will see how to find it...

Objective: Given a binary tree, print all nodes will are full nodes. Full Nodes: Nodes Which has both the children, left and right are called Full Nodes Approach: quite simple Solution. Do the any...

Objective: – Given “n”, generate all valid parenthesis strings of length “2n”. Example: Given n=2 Output: (()) ()() Approach:

The Tower of Hanoi is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The objective of the puzzle...

Objective: – Generate All Strings of n bits, consider A[0..n-1] is an array of size n. Example : n = 3 Output: [0, 0, 0] [1, 0, 0] [0, 1, 0] [1, 1, 0]...

The greatest common divisor (GCD) of two or more integers, when at least one of them is not zero, is the largest positive integer that divides the numbers without a remainder. For example, the...

Objective: – Given a binary tree, print it in Bottom View of it. What is Bottom View: Bottom view means when you look the tree from the bottom the nodes you will see will be...

Objective: Given a Linked List, Sort it using merge sort. Example: ->9->3->4->2->5->1 Sorted List: ->1->2->3->4->5->9 Approach: Reference : Merge Sort in array

What is AVL Tree : AVL tree is widely known as self-balancing binary search tree. It is named after its creator (Georgy Adelson-Velsky and Landis’ tree). In AVL Tree, the heights of child subtrees...