From 74d7e93da3077bb46d0a60fff7ccc7a919957e1d Mon Sep 17 00:00:00 2001 From: ritwik1503 <35749253+ritwik1503@users.noreply.github.com> Date: Fri, 2 Oct 2020 05:04:44 +0530 Subject: [PATCH] Update Book_Allocation.md --- Binary Search/Book_Allocation.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Binary Search/Book_Allocation.md b/Binary Search/Book_Allocation.md index 1886801..ea71848 100644 --- a/Binary Search/Book_Allocation.md +++ b/Binary Search/Book_Allocation.md @@ -51,7 +51,9 @@ int findMinPages(int *books,int n,int k){ int ans = INT_MAX; while(s<=e){ - mid = (s+e)/2; + //Mid should be considered like this in order to avoid Integer overflow that can be caused. + // If both s and e are INT_MAX. If we take mid = (s+e)/2 , this will cause overflow and give WA. + mid = s + (e-s)/2; if(isValid(books,n,k,mid)){ ans =