fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int arr[]= {10,5,2,7,1,9};
  6. int n=sizeof(arr)/sizeof(arr[0]);
  7. int k=15;
  8. int largest=INT_MIN, smallest=INT_MAX;
  9. for(int i=0;i<n;i++){
  10. int currSum=0;
  11. for(int j=i;j>=0;j--){
  12. currSum+=arr[j];
  13. if(currSum==k){
  14. largest=max(largest,i-j+1);
  15. smallest=min(smallest, i-j+1);
  16. }
  17. }
  18. }
  19. cout<<largest<<" "<<smallest;
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 5308KB
stdin
Standard input is empty
stdout
4 2