Practice
Resources
Contests
Online IDE
New
Free Mock
Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
Scaler
Explore Offerings by SCALER

Go to Problems

# Characteristics of Dynamic Programming

Before moving on to approaches to solve a DP problem, let us have a look at the characteristics of a problem upon which we can apply the DP technique.

We can apply DP technique to those problems that exhibit the below 2 characteristics:

### 1. Optimal Substructures

• Any problem is said to be having optimal substructure property if its overall optimal solution can be evaluated from the optimal solutions of its subproblems.
• Consider the example of Fibonacci Numbers.
• We know that a nthÂ Fibonacci number (Fib(n)) is nothing but sum of previous 2 fibonacci numbers, i.e:Â `Fib(n) = Fib(n-1) + Fib(n-2)`.Â

• From the above equation, we can clearly deduce that a problem of size â€˜nâ€™ has been reduced to subproblems of size â€˜n-1â€™ and â€˜n-2â€™.

• Hence, we can say that Fibonacci numbers have the optimal substructure property.

### 2. Overlapping Subproblems

• Subproblems are basically the smaller versions of an original problem. Any problem is said to have overlapping subproblems if calculating its solution involves solving the same subproblem multiple times.
• Let us take the example of finding nthÂ Fibonacci number. Consider evaluating Fib(5). As shown in the breakdown of steps shown in the image below, we can see that Fib(5) is calculated by taking sum of Fib(4) and Fib(3) and Fib(4) is calculated by taking sum of Fib(3) and Fib(2) and so on. Clearly, we can see that the Fib(3), Fib(2), Fib(1) and Fib(0) has been repeatedly evaluated. These are nothing but the overlapping subproblems.Â
``Note: It is important for a problem to have BOTH the above specified characteristics in order to be eligible to be solved using DP technique.``

## Serious about Learning Programming ?

Learn this and a lot more with Scaler Academy's industry vetted curriculum which covers Data Structures & Algorithms in depth.

## Dynamic Programming Problems

2d string dp
Greedy or dp
Problem Score Companies Time Status
Tushar's Birthday Bombs 200
78:46
Jump Game Array 225 41:16
Min Jumps Array 300 71:51
Tree dp
Problem Score Companies Time Status
Max edge queries! 200 56:13
Max Sum Path in Binary Tree 400 55:11
Suffix / prefix dp
Problem Score Companies Time Status
Sub Matrices with sum Zero 200
74:03
Coin Sum Infinite 225 64:48
Max Product Subarray 300 65:15
Best Time to Buy and Sell Stocks I 300 28:13
Arrange II 350 72:05
Derived dp
Problem Score Companies Time Status
Chain of Pairs 200 42:56
Max Sum Without Adjacent Elements 225 58:13
Merge elements 300 60:03
Knapsack
Problem Score Companies Time Status
Flip Array 200
79:34
Tushar's Birthday Party 200 71:36
0-1 Knapsack 200 48:24
Equal Average Partition 350 72:09
Dp
Problem Score Companies Time Status
Potions 200 56:35
Problem Score Companies Time Status
Best Time to Buy and Sell Stocks II 225 40:18
Dp optimized backtrack
Problem Score Companies Time Status
Word Break II 350 67:47
Multiply dp
Problem Score Companies Time Status
Unique Binary Search Trees II 400 36:14
Count Permutations of BST 400
62:03
Breaking words
Problem Score Companies Time Status
Palindrome Partitioning II 400 62:22
Word Break 400 67:21

Problem Score Companies Time Status
Double Increasing Series 200 43:59
Dice Rolls 300 27:43
Palindromic Substrings 200 26:35
Free Mock Assessment
Fill up the details for personalised experience.
All fields are mandatory
Current Employer *
Enter company name *
Select an option *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
Phone Number *
OTP will be sent to this number for verification
+91 *
+91
Change Number
Phone Number *
OTP will be sent to this number for verification
+91 *
+91
Change Number
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
*Enter the expected year of graduation if you're student
Current Employer *
Company Name *