(int a[], int n, int x)
| 2 | class Solution { |
| 3 | |
| 4 | public static int sb(int a[], int n, int x) { |
| 5 | // Your code goes here |
| 6 | |
| 7 | int start=0,end=1; |
| 8 | int result=Integer.MAX_VALUE; |
| 9 | int sum=a[start]; |
| 10 | if(sum>x) return 1; |
| 11 | if(end<n) sum+=a[end]; |
| 12 | |
| 13 | while(start<n && end<n) |
| 14 | { |
| 15 | if(sum>x) |
| 16 | { |
| 17 | result = Math.min(result,end-start+1); |
| 18 | sum-=a[start]; |
| 19 | start++; |
| 20 | } |
| 21 | else |
| 22 | { |
| 23 | end++; |
| 24 | if(end<n) |
| 25 | { |
| 26 | sum+=a[end]; |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | return result; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | //Leetcode solution |
nothing calls this directly
no outgoing calls
no test coverage detected