Interview Bootcamp
Ask Author
Back to course home

0% completed

Vote For New Content
I think there is a better solution for Smallest Subarray with a Greater Sum (eas...

Syed Hassan

Jan 13, 2022

I think there is a better solution for

Smallest Subarray with a Greater Sum (easy)

We dont have to use two loops, even though the inner one runs only once. Can you please suggest if this function is ok? public int smallest(int[] array , int tarSum) {

int smallest_Elements = 0; int sum=0; int startPtr = 0; // O (N) for(int endPtr =0;endPtr=tarSum) { int currentElements = (endPtr - startPtr)+1; if(smallest_Elements==0 || currentElementsendPtr) { endPtr = startPtr; endPtr--; } }

}

return smallest_Elements;

}

0

0

Comments
Comments
B
Bryan Pena3 years ago

I dont understand the logic behind using the math.in and the integer.max_value. can someone please explain how this works