Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the low boundary for binary search as the maximum pages in a single book.
DSA Java
int low = [1]; // max pages in a single book
Attempts:
3 left
💡 Hint
Common Mistakes
Setting low to 0 or sum of pages instead of max pages.
Using pages.length which is the number of books, not pages.
✗ Incorrect
The low boundary is the maximum pages in any single book because no student can be assigned less than that.
2fill in blank
mediumComplete the code to initialize the high boundary for binary search as the sum of all pages.
DSA Java
int high = [1]; // sum of all pagesAttempts:
3 left
💡 Hint
Common Mistakes
Using max pages instead of sum for high boundary.
Using pages.length which is count of books, not pages.
✗ Incorrect
The high boundary is the total pages of all books, representing the maximum pages one student can read if assigned all books.
3fill in blank
hardFix the error in the condition to check if current mid value can be a valid maximum pages allocation.
DSA Java
if (isPossible(pages, students, [1])) {
Attempts:
3 left
💡 Hint
Common Mistakes
Passing low or high instead of mid to isPossible.
Passing students count instead of pages limit.
✗ Incorrect
We check if the mid value can be a valid maximum pages allocation for the students.
4fill in blank
hardFill both blanks to update the binary search boundaries after checking feasibility.
DSA Java
if (isPossible(pages, students, mid)) { result = mid; [1] = mid - 1; } else { [2] = mid + 1; }
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping low and high updates.
Updating result instead of low or high.
✗ Incorrect
If mid is possible, we update result to mid and try for a lower value by setting high = mid - 1. Otherwise, we increase low to mid + 1.
5fill in blank
hardFill all three blanks to complete the isPossible function that checks if allocation is feasible with max pages limit.
DSA Java
int studentCount = 1; int currentSum = 0; for (int page : pages) { if (currentSum + page > [1]) { studentCount++; currentSum = page; if (studentCount > [2]) { return [3]; } } else { currentSum += page; } } return true;
Attempts:
3 left
💡 Hint
Common Mistakes
Returning true instead of false when students exceed limit.
Using wrong variable names for max pages or students.
✗ Incorrect
We check if assigning pages exceeds maxPages, increase student count, and if students exceed limit, return false.
