Thursday, 3 September 2020

Cheapest Subarray hacker earth solution in C

https://www.hackerearth.com/practice/basic-programming/implementation/basics-of-implementation/practice-problems/algorithm/cheapest-subarray-d628cb65/submissions/?utm_source=header&utm_medium=search&utm_campaign=he-search 


#include<stdio.h>

void main ()
{
    int t;
    scanf("%d",&t);
    while (t--)
    {
        int n;
        scanf("%d",&n);
        int a[n],i=0;
        scanf("%d",&a[i]);
        for (i=1;i<n;i++)
        {
            
            scanf("%d",&a[i]);
            a[i-1]= a[i-1] + a[i];
            
        }
        int min = a[0];
        for (i=1;i<n-1;i++)
            if (min>a[i])
                min = a[i];
        
        printf("%d\n",min);
    }
}

1 comment: