Building Bridges
In this tutorial we shall solve building bridges problem with help of DP. This is a classical DP problem. Problem statement: Given a river, you need to build a bridge across the river in such a way that only he pair given can form a bridge, and no bridges should be crossing each other. Example, […]
Box Stacking Problem
This is a classical DP problem. In this tutorial we shall see how to solve box stacking problem. We shall solve it by DP approach. Problem Statement: You are given n number of boxes, and you need to place the boxes on top of each other such that you get the maximum height and by […]
Rod Cutting Problem
In this tutorial we shall learn about rod cutting problem. Problem statement: You are given a rod of length n and you need to cut the cod in such a way that you need to sell It for maximum profit. You are also given a price table where it gives, what a piece of rod […]
Get Max Coin In Game problem.
In this chapter we shall solve how to get maximum coin in a game problem with help of DP. Problem Statement: You and your friend are playing a game to pick numbers from an array of even length. You need to find a solution so that you can pick the maximum sum and you win […]
Longest Bitonic Subsequence
In this tutorial we shall solve longest Bitonic subsequence using DP. Before solving the question, let’s understand what does Bitonic means. Bitonic is a sequence where the number increases at certain point and decreases from that point. For example: Consider the array below Here if you see the highlighted numbers as shown below: They are […]
Dynamic Programming: Longest Increasing Subsequence
In this tutorial we shall look at longest increasing subsequence and we shall solve it by using Dynamic Programming. Problem Statement: You are given an array of integers; you need to find the longest increasing subsequence. It means that, you need to find a sub array in sorted whose sum is max. Example: Output: Here […]
Print the nodes at k distance from the root of a binary tree
In this tutorial we shall see how to print all the nodes that is k distance from root. Problem statement: Given the root node and the distance k, print all the nodes that are at distance k from root node. Consider the image below: So according to the image, root is at level 0, below […]
Print all the paths from root node to leaf node
In this chapter we shall see how to print all the paths from root to leaf nodes. Problem Statement: You are given the root node of a binary tree, you need to print all the paths from root node to leaf nodes. Consider the example below: Now according to the image, we have root node […]
Print the number of leaf nodes in a binary tree
In this chapter we shall print the number of leaf nodes in a binary tree. Problem Statement: You are given the root node of the tree. You need to return the total number of leaf nodes present in that tree. Example: Consider the below tree In the above tree, there are 4 leaf nodes. d, […]
Add all the node values in a Binary Tree or Sum of a Binary tree
In this chapter, we shall see how to add all the nodes value. Problem Statement: Given a binary tree root node, return the sum of all the nodes of the tree. Example: Consider the tree below: The total sum will be 7 + 36 + 1 + 2 + 4 + 5 = 64 Now […]