-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathcode_1.cpp
60 lines (51 loc) · 1.36 KB
/
code_1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// code_1.cpp
// Algorithm
//
// Created by Mohd Shoaib Rayeen on 23/11/18.
// Copyright © 2018 Shoaib Rayeen. All rights reserved.
//
#include <iostream>
#include <vector>
using namespace std;
struct Interval {
int start, end;
};
void getMinMaxInRanges(vector<int> array , vector<Interval> list) {
int numberOfRange = int(list.size());
int min , max;
for ( int i = 0; i < numberOfRange; i++) {
min = array[list[i].start];
max = min;
for ( int j = list[i].start + 1; j <= list[i].end; j++ ) {
if ( array[j] < min ) {
min = array[j];
}
if ( array[j] > max ) {
max = array[j];
}
}
cout << "\nFor Range ( " << list[i].start << " , " << list[i].end << ")\nMinimum\t:\t" << min;
cout << "\nMaximum\t:\t" << max << endl;
}
}
int main() {
int n;
cout << "\nEnter Size of Array\t:\t";
cin >> n;
vector<int> arr(n);
cout << "\nEnter Array Elements\n";
for (int i = 0; i < n; i++ ) {
cin >> arr[i];
}
cout << "\nEnter Number of Intervals\t:\t";
cin >> n;
vector<Interval> array(n);
cout << "\nEnter Range (L,R) Form\n";
for (int i = 0; i < n; i++ ) {
cin >> array[i].start;
cin >> array[i].end;
}
getMinMaxInRanges(arr, array);
return 0;
}