Hints Required for logic formation

Could u provide some hints along with some examples for this question.

Hey try to go through this video


if this solves your doubt please mark it as resolved :slight_smile:

I am not able to watch the video, as their is no option available to play the video. could u please send the link for the video

here:
https://www.youtube.com/watch?v=Ss9ta1zmiZo

My code is still not working could you review my code and tell me what is missing in it?

import java.util.*; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int T = s.nextInt(); while(T–>0){ int n = s.nextInt(); int m = s.nextInt(); int[] bookPage = new int[n]; int totalPage = 0; for(int i = 0 ; i < n ; i++){ bookPage[i] = s.nextInt(); totalPage += bookPage[i]; } int low = bookPage[n-1]; int high = totalPage; int ans = 0; while(low < high){ int stucnt = 1; int current_pages = 0; int mid = (low+high)/2; for(int i = 0 ; i < n ; i++){ if(current_pages+bookPage[i] > mid){ current_pages = bookPage[i]; stucnt++; } else{ current_pages += bookPage[i]; } if(stucnt > m){ break; } } if(stucnt == m){ high = mid-1; ans = mid; } else{ low = mid+1; } } System.out.println(ans); } } }

please share your code by saving it on ide.codingblocks.com

Here’s the link for the code : https://ide.codingblocks.com/s/381569

use long to incorporate the constraints

I am still not getting the right answer , i have made the necessary changes , Please check the code : https://ide.codingblocks.com/s/382616

see this: