Showing posts with label Breaking Records Hacker Rank Solution in C. Show all posts
Showing posts with label Breaking Records Hacker Rank Solution in C. Show all posts

Friday, 24 November 2017

Breaking Records Hacker Rank Solution in C

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>



int main() {
    int n,result_size=2,max,min;
    scanf("%d",&n);
    int *s = malloc(sizeof(int) * n);
    int result[2];
    result[0]=0;
    result[1]=0;
    for(int s_i = 0; s_i < n; s_i++){
       scanf("%d",&s[s_i]);
        if(s_i == 0)
            max=min=s[s_i];
        else
        {
            if(s[s_i]> max)
            {
                result[0]++;
                max=s[s_i];
            }
            if(s[s_i]< min)
            {
                result[1]++;
                min=s[s_i];
            }
        }
    }
  
  
    for(int i = 0; i < result_size; i++) {
        if (i) {
            printf(" ");
        }
        printf("%d", result[i]);
    }
    puts("");
    return 0;
}