Lecture
Coding Quiz - 1, 2, 3 Addition
In this coding problem, you will write a function using Dynamic Programming (DP) to find the number of ways to form a specific number.
For a given number n, you need to calculate all the possible ways to make n with the sum of 1, 2, and 3.
For example, when n = 4, the possible combinations are 1+1+1+1, 1+1+2, 1+2+1, 2+1+1, 2+2, 1+3, and 3+1, totaling 7 ways.
Solution Code
def solution(n): # Write your code here return
Constraints
-
nis an integer between 1 and 10, inclusive. -
The result should be returned as an integer.
Example Input and Output
-
Input:
4 -
Output:
7
-
Input:
6 -
Output:
24
Previous lessonExplanation for Recursively Calculating the Sum of a ListNext lessonExplanation for Adding 1, 2, 3
Lessons in this chapter · Practice with Common Coding Quiz Types
- 1. Coding Quiz - Finding Rotten Apples
- 2. Finding Rotten Apples Explained
- 3. Coding Quiz - Calculating the Sum of a List Recursively
- 4. Explanation for Recursively Calculating the Sum of a List
- 5. Coding Quiz - 1, 2, 3 Addition
- 6. Explanation for Adding 1, 2, 3
- 7. Coding Quiz - Flattening a 2D Array
- 8. Converting to a 1D Array Explanation
- 9. Coding Quiz - Calculate the Sum of a List Using Divide and Conquer
- 10. Explanation of Calculating the Sum of a List Using Divide and Conquer
- 11. Coding Quiz - Gym Uniform Problem
- 12. Gym Uniform Problem Explanation
- 13. Coding Quiz - List of Integers with Sum Greater than Target
- 14. Explanation of Integer List with Sum Greater Than Target
- 15. Coding Quiz - Finding Travel Routes
- 16. Finding Travel Itinerary Explanation
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help