Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the dp vector with 1s for each element.
DSA Rust
let mut dp = vec![[1]; nums.len()];
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing dp with 0s instead of 1s.
Using the length of nums as the initial value.
✗ Incorrect
Each element starts with a subsequence length of 1 (the element itself).
2fill in blank
mediumComplete the code to compare current element nums[i] with nums[j].
DSA Rust
if nums[i] [1] nums[j] {
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= or >= which includes equal or wrong direction.
Using < which is the wrong direction.
✗ Incorrect
We look for increasing subsequences, so nums[i] must be greater than nums[j].
3fill in blank
hardFix the error in updating dp[i] to the maximum subsequence length.
DSA Rust
dp[i] = dp[i].[1](dp[j] + 1);
Attempts:
3 left
💡 Hint
Common Mistakes
Using min instead of max.
Trying to sum or power which is incorrect.
✗ Incorrect
We update dp[i] to the maximum length found so far.
4fill in blank
hardFill both blanks to find the maximum value in dp after processing.
DSA Rust
let result = dp.iter().[1]().[2]();
Attempts:
3 left
💡 Hint
Common Mistakes
Using min instead of max.
Not cloning or copying before max causing type errors.
✗ Incorrect
We clone the iterator items to get values, then find the max.
5fill in blank
hardFill both blanks to complete the nested loops for LIS calculation.
DSA Rust
for i in 1..nums.len() { for j in 0..[1] { if nums[i] > nums[j] { dp[i] = dp[i].max(dp[j] [2] 1); } } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using i-1 instead of i in inner loop range.
Using subtraction instead of addition when updating dp[i].
✗ Incorrect
Inner loop runs from 0 to i-1, and we add 1 to dp[j] to extend subsequence.
