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; }
Thnx
ReplyDeletegood logic
ReplyDeletebut code is not working INT_MAX is unitialized
Deletecode is working on both ideone and got accepted at hackerrank. INT_MAX is a constant defined under (limits.h) header:
Delete1 - 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