Thursday, April 17, 2014

Hackerrank Service Lane solution

Hackerrank Service Lane: https://www.hackerrank.com/challenges/service-lane

Hackerrank Service Lane solution: http://ideone.com/zMEYzV


#include <iostream>
#include <cstdio>
#include <climits>
using namespace std;

int main() {
    int t, n, a[100001], l, r, min;
    scanf("%d%d", &n, &t);
    for(int i=0; i<n; i++) scanf("%d", &a[i]);
    while(t--) {
        min=INT_MAX;
        scanf("%d%d", &l, &r);
        for(int i=l; i<=r; i++) if(a[i]<min) min=a[i];
        printf("%d\n", min);
    }
    return 0;
}

4 comments:

  1. Replies
    1. but code is not working INT_MAX is unitialized

      Delete
    2. code is working on both ideone and got accepted at hackerrank. INT_MAX is a constant defined under (limits.h) header:
      1 - http://www.cplusplus.com/reference/climits/
      2 - http://stackoverflow.com/questions/1855459/maximum-value-of-int
      3 - http://www.cplusplus.com/forum/beginner/84756/
      4 - https://msdn.microsoft.com/en-us/library/296az74e.aspx

      Delete