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

Welcome to Interviewbit, help us create the best experience for you!

Currently, You are a:

Few details about your education

College/University *
Enter the name of your college
Branch *
Year of completion *

Few details about your education

College/University *
Enter the name of your college
Branch *
Year of completion *

Few details about your career...

Current Company *
Enter company name
Experience *

You're all set!

Begin your success journey!

Sign Up using
Full name *
Email *
Password *

By creating an account, I acknowledge that I have read and agree to InterviewBit’s Terms and Privacy Policy .

Welcome back!

Log In using
Email *
Password *

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:13
Jump Game Array 225 41:16
Min Jumps Array 300 71:44
Tree dp
Problem Score Companies Time Status
Max edge queries! 200 56:34
Max Sum Path in Binary Tree 400 55:07
Suffix / prefix dp
Derived dp
Problem Score Companies Time Status
Chain of Pairs 200 42:09
Max Sum Without Adjacent Elements 225 58:10
Merge elements 300 57:43
Knapsack
Problem Score Companies Time Status
Flip Array 200
78:42
Tushar's Birthday Party 200 70:50
0-1 Knapsack 200 47:57
Equal Average Partition 350 71:48
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:29
Multiply dp
Problem Score Companies Time Status
Unique Binary Search Trees II 400 36:06
Count Permutations of BST 400
62:18
Breaking words
Problem Score Companies Time Status
Palindrome Partitioning II 400 62:02
Word Break 400
IBM
67:00

Additional Practice

Problem Score Companies Time Status
Potions 200 56:52
Dice Throw 400 49:10
Double Increasing Series 200 45:07
Dice Rolls 300 27:32
Palindromic Substrings 200
LTI
25:36
Free Mock Assessment
Help us know you better for the best experience
Current Employer *
Enter company name
College you graduated from *
Enter university name
Phone Number *
OTP will be sent to this number for verification
+1
+1
Change Number
Edit
Resend OTP
By Continuing I agree to be contacted by Scaler in the future.
Already have an account? Log in