Doubt in the code

please check my code ,half of my test cases are running,I applied binary search in this question please check

hey @Adhyayan
code is almost correct
some Changes

why are you taking left=0;
it is known that the answer cannot be less then max element of array??
please explain your code properly…

why are you taking left=0;// min length
boolean f = false;
for(int j=0;j<n;){
if(sum1+arr[j]<=mid){ //mera Change
// if(sum1>mid){

				sum1+=arr[j];
				j++;
			}
            else{
                sum1=0;
                 c++;
            }
			if(c>p) { // No of painter >p i,e increase length of board 
				f=true;
				break;
			}

	
		}
		if(f) {
			left=mid+1;
		}

else{
ans=mid;

			right=mid-1;
		}