class Solution { public int minimumSize(int[] nums, int maxOperations) { Arrays.sort(nums); int left = 1, right = nums[nums.length - 1]; while(left < right) { int mid = left + (right - left) / 2; if(isvalid(nums, mid, maxOperations)) { right = mid; } else { left = mid + 1; } } return left; } private boolean isvalid(int[] nums, int mid, int maxo) { int c = 0; for(int i : nums) { if(i > mid) { c += (i - 1) / mid; } } return c
class Solution {
public int minimumSize(int[] nums, int maxOperations) {
Arrays.sort(nums);
int left = 1, right = nums[nums.length - 1];
while(left < right)
{
int mid = left + (right - left) / 2;
if(isvalid(nums, mid, maxOperations))
{
right = mid;
}
else
{
left = mid + 1;
}
}
return left;
}
private boolean isvalid(int[] nums, int mid, int maxo)
{
int c = 0;
for(int i : nums)
{
if(i > mid)
{
c += (i - 1) / mid;
}
}
return c
I think the logic is little confusive. Keep an eye on the logic once again