Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the maximum revenue list with zeros.
DSA Python
max_revenue = [[1]] * (n + 1)
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing with 1 instead of 0, which incorrectly assumes some revenue.
Using negative values which don't make sense for revenue.
✗ Incorrect
We initialize max_revenue with zeros because initially, the maximum revenue for all lengths is zero before calculation.
2fill in blank
mediumComplete the code to loop through all possible first cut lengths.
DSA Python
for i in range(1, [1] + 1):
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable like max_revenue or prices in the loop range.
Starting the loop from 0 instead of 1.
✗ Incorrect
We loop from 1 to n because we consider all possible first cut lengths from 1 up to the full rod length n.
3fill in blank
hardFix the error in updating the maximum revenue for length j.
DSA Python
max_revenue[j] = max(max_revenue[j], prices[i - 1] + [1][j - i])
Attempts:
3 left
💡 Hint
Common Mistakes
Using prices instead of max_revenue for the remaining length.
Using j or i incorrectly as an index.
✗ Incorrect
We add the price of the first cut (prices[i - 1]) to the maximum revenue of the remaining length (max_revenue[j - i]).
4fill in blank
hardFill both blanks to complete the nested loop structure for the rod cutting solution.
DSA Python
for j in range([1], n + 1): for i in range(1, [2] + 1):
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the loop variables or using incorrect ranges.
Using n in the inner loop instead of the current rod length.
✗ Incorrect
The outer loop runs over rod lengths j from i to n, and the inner loop runs over possible cut lengths i from 1 to j.
5fill in blank
hardFill both blanks to complete the dictionary comprehension that maps rod lengths to their maximum revenues.
DSA Python
result = { [1] for [2] in range(1, n + 1)}Attempts:
3 left
💡 Hint
Common Mistakes
Missing braces or using incorrect variable names.
Confusing keys and values in the comprehension.
✗ Incorrect
We create a dictionary with keys as lengths and values as maximum revenues using a comprehension enclosed in braces.
