July 02, 2018
Problem:
Idea is to use Greedy Approach and tie node of consecutive ropes.
Code:
public int solution(int k, int[] a) {
int count=0;
for(int i=0;i<a.length;++i)
{
if(a[i]>=k)
{
++count;
continue;
}
if(i+1<a.length)
a[i+1]+=a[i];
}
return count;
}
0 Comments:
Post a Comment