Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the left pointer for the sliding window.
DSA Rust
let mut left = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Starting left pointer at 1 skips the first character.
Using negative index is invalid in Rust.
Setting left to string length causes out-of-bound errors.
✗ Incorrect
The left pointer should start at 0 to begin scanning from the start of the string.
2fill in blank
mediumComplete the code to update the count of characters in the current window.
DSA Rust
window_counts.insert(c, window_counts.get(&c).unwrap_or(&0) + [1]);
Attempts:
3 left
💡 Hint
Common Mistakes
Adding 0 does not update the count.
Adding -1 decreases the count incorrectly.
Adding 2 counts characters twice.
✗ Incorrect
We add 1 to the current count of character c in the window.
3fill in blank
hardFix the error in the condition to check if the current window contains all required characters.
DSA Rust
if formed == required [1] {
Attempts:
3 left
💡 Hint
Common Mistakes
Using != causes the condition to fail when window is valid.
Using < misses windows that exactly match requirements.
Using == false reverses the logic incorrectly.
✗ Incorrect
We check if formed equals required to confirm the window has all needed characters.
4fill in blank
hardFill both blanks to correctly shrink the window from the left and update counts.
DSA Rust
let c = s.chars().nth(left).unwrap(); window_counts.insert(c, window_counts.get(&c).unwrap() [1] 1); if window_counts.get(&c).unwrap() [2] target_counts.get(&c).unwrap_or(&0) [3] 0 { formed -= 1; }
Attempts:
3 left
💡 Hint
Common Mistakes
Adding instead of subtracting increases count incorrectly.
Using > instead of < reverses the condition logic.
Not updating formed causes incorrect window validation.
✗ Incorrect
We subtract 1 from the count of c, then check if it is less than the required count to reduce formed.
5fill in blank
hardFill all three blanks to update the minimum window substring result correctly.
DSA Rust
if right - left + 1 < ans.[1] { ans.[2] = right - left + 1; ans.[3] = left; }
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing tuple indices causes wrong updates.
Using 'length' instead of numeric indices causes errors.
Not updating ans correctly leads to wrong final substring.
✗ Incorrect
ans is a tuple where ans.0 stores the window length, ans.1 the start index, and ans.2 the end index.
