New update is available. Click here to update.
About
just I am coding learner .
Quantum University 2026
My Stats
EXP gained
2111
Level
5 (Champion)
Community stats
Discussions
0
Upvotes
0
Know more
Weekend contest rating
Contest attended
Problems solved
2021 2023
Better than %
Weekend contest rating
Contest attended
Problems solved
2021 2023
Better than %
53
Total problems solved
47
Easy
6
Moderate
0
Hard
0
Ninja

Current streak:

0 days

Longest streak:

3 days

Less

More

Achievements
1
Ronin
Topics
Arrays
Discussions
this code is not run any error what is change and what is wrong in this program
Interview problems
``````#include <bits/stdc++.h>
using namespace std;
bool ayushGivesNinjatest(vector<int>time,int n,int m, int mid){

int studentCount = 1;
int pageSum = 0;

for(int i=0;i<n;i++) {
if(pageSum + time[i] <= mid) {
pageSum += time[i];
}
else {
studentCount++;
if(studentCount > m|| time[i] > mid){
return false;
}
pageSum = time[i];
}
if(studentCount >m){
return false;
}
//cout << "allocateBooks" << endl;
}
return true;
}

int ayushGivesNinjatest(int n, int m, vector<int> time)
{
int s = 0;
int sum = 0;

for(int i = 0; i < n; i++) {
sum += time[i];
}
int e = sum;
int ans = -1;
int mid = s+(e - s)/2;

while(s<=e) {

if(ayushGivesNinjatest(time,n,m,mid)){

ans = mid;
e = mid - 1;
}
else
{
s = mid + 1;
}

mid = s +(e - s)/2;
}
return ans;
}``````
kshna0i
Published On 28-Oct-2023
106 views
4 replies
1 upvotes