Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int smallestSubWithSum(int arr[], int n, int x)
- {
- // Your code goes here
- int k=0;
- int kk=0;
- int sum=0;
- int ans = INT_MAX;
- while(true)
- {
- if(sum > x)
- { if (k >n-1)
- break;
- sum-=arr[k];
- k++;
- ans= min(ans,kk-k+1);
- }
- else
- { if(kk>n-1)
- break;
- sum+=arr[kk];
- kk++;
- }
- }
- if(ans == INT_MAX)
- return 0;
- return ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement