Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the maximum area variable.
DSA Rust
let mut max_area = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Initializing max_area with a negative number.
Using usize::MAX which is too large and incorrect here.
✗ Incorrect
We start with max_area as 0 because initially we have no container formed.
2fill in blank
mediumComplete the code to calculate the width between two pointers.
DSA Rust
let width = [1] - left;Attempts:
3 left
💡 Hint
Common Mistakes
Using left - right which can cause underflow.
Using max_area or height instead of indices.
✗ Incorrect
Width is the distance between the right and left pointers.
3fill in blank
hardFix the error in the code to update the maximum area correctly.
DSA Rust
max_area = max_area.[1](area);Attempts:
3 left
💡 Hint
Common Mistakes
Using min which would keep the smaller area.
Using sum or abs which are not methods on integers.
✗ Incorrect
We use max to keep the largest area found so far.
4fill in blank
hardFill both blanks to move the pointers correctly based on height comparison.
DSA Rust
if height[left] < height[right] { left = left [1] 1; } else { right = right [2] 1; }
Attempts:
3 left
💡 Hint
Common Mistakes
Moving pointers in wrong directions.
Using multiplication or division instead of addition or subtraction.
✗ Incorrect
If left height is smaller, move left pointer right (+1). Else move right pointer left (-1).
5fill in blank
hardFill all three blanks to complete the area calculation and loop condition.
DSA Rust
while [1] < [2] { let h = std::cmp::min(height[[1]], height[[2]]); let width = [2] - [1]; let area = h * width; max_area = max_area.max(area); if height[[1]] < height[[2]] { [1] += 1; } else { [2] -= 1; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up left and right variables.
Using max_area or height incorrectly in loop condition.
✗ Incorrect
The loop runs while left < right. Height uses height[left] and height[right]. Width is right - left.
