Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find the maximum number of pages in any single book.
DSA Rust
let max_pages = *books.iter().[1]().unwrap();Attempts:
3 left
💡 Hint
Common Mistakes
Using min() instead of max()
Using sum() which returns total pages
Using count() which returns number of books
✗ Incorrect
We use iter().max() to find the maximum pages in any book, which is the lower bound for allocation.
2fill in blank
mediumComplete the code to check if allocation is possible with given max pages per student.
DSA Rust
if allocate(books, students, [1]) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using max_pages or min_pages directly instead of mid
Using total_pages which is sum of all pages
✗ Incorrect
We check allocation feasibility with mid as the maximum pages allowed per student.
3fill in blank
hardFix the error in the allocation function to correctly count students needed.
DSA Rust
if current_sum + book > [1] { students_needed += 1; current_sum = book; } else { current_sum += book; }
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with max_pages or total_pages instead of mid
Not resetting current_sum correctly
✗ Incorrect
We compare current sum plus book pages to mid, the max pages allowed per student.
4fill in blank
hardFill both blanks to update binary search bounds correctly after allocation check.
DSA Rust
if allocate(books, students, mid) { result = mid; [1] = mid + 1; } else { [2] = mid - 1; }
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping low and high updates
Updating mid instead of low or high
✗ Incorrect
If allocation is possible, move low up to mid+1 to try for a better answer; else move high down to mid-1.
5fill in blank
hardFill both blanks to complete the binary search loop for minimum pages allocation.
DSA Rust
let mut low = [1]; let mut high = [2]; let mut result = high; while low <= high { let mid = (low + high) / 2; if allocate(books, students, mid) { result = mid; low = mid + 1; } else { high = mid - 1; } } result
Attempts:
3 left
💡 Hint
Common Mistakes
Setting low to 0 instead of max_pages
Setting high to max_pages instead of total_pages
Initializing result incorrectly
✗ Incorrect
low starts at max_pages (maximum pages in any single book), high at total_pages (sum of all pages), result initialized to high.
