Accenture Coding Question 21

4 comments on “Accenture Coding Question 21”


  • Ashish

    kindly make an option to hover over previous or next questions. It is very hectic to go back and find the question again.


  • Shrutika

    #include
    #include
    using namespace std;

    int fun(int arr1[],int size, int k1){

    if(k1size){
    return 0;
    }

    vector minsum;

    for(int i=0;i<=size-k1;i++){
    int sum=0;
    for(int j=i; j<i+k1; j++){
    cout<<arr1[j]<<" ";
    sum+=arr1[j];

    }
    minsum.push_back(sum);
    cout<<endl;
    }
    sort(minsum.begin(), minsum.end());

    return minsum[0];
    }

    int main(){
    int n=7;
    int k=3;
    int arr[n]={3, 2, 1, -4, 6, 3, 1};
    cout<<fun(arr,n,k);
    return 0;
    }