MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / isValid

Method isValid

CapacityToShipPackagesWithInDDays.java:2–18  ·  view source on GitHub ↗
(int cap,int weights[],int days,int n)

Source from the content-addressed store, hash-verified

1class Solution {
2 public boolean isValid(int cap,int weights[],int days,int n)
3 {
4 int numDays=0;
5 int sumOfWeights=0;
6 for(int i=0;i<n;i++)
7 {
8 if(weights[i]>cap) return false;
9 sumOfWeights+=weights[i];
10 if(sumOfWeights>cap)
11 {
12 numDays++;
13 sumOfWeights=weights[i];
14 }
15 }
16 numDays++;
17 return numDays<=days;
18 }
19 public int shipWithinDays(int[] weights, int days) {
20
21 int minCap=Integer.MIN_VALUE;

Callers 1

shipWithinDaysMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected