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

Dynamic Programming

Go to Problems

Level 1

Jump to Level 2

Level 2

Jump to Level 3

Level 3

Jump to Level 4

Level 4

Jump to Level 5

Level 5

Jump to Level 6

Level 6

Jump to Level 7

Level 7

Jump to Level 8

Level 8

Be a Code Ninja!

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. Fib(5)
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

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
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
Adhoc
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
IBM
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
IBM
67:21

Additional Practice

Problem Score Companies Time Status
Double Increasing Series 200 43:59
Dice Rolls 300 27:43
Palindromic Substrings 200
LTI
26:35
Free Mock Assessment
Fill up the details for personalised experience.
All fields are mandatory
Current Employer *
Enter company name *
Graduation Year *
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
Graduation Year *
Graduation Year *
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 *
Please verify your phone number
Edit
Resend OTP
By clicking on Start Test, I agree to be contacted by Scaler in the future.
Already have an account? Log in
Free Mock Assessment
Instructions from Interviewbit
Start Test