-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path7_Question.cpp
More file actions
62 lines (41 loc) · 1.33 KB
/
7_Question.cpp
File metadata and controls
62 lines (41 loc) · 1.33 KB
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
59
60
61
62
// Given an integer array Arr of size N the task is to find the count of elements whose value is greater than all
// of its prior elements.
// Note : 1st element of the array should be considered in the count of the result.
// For example,
// Arr[]={7,4,8,2,9}
// As 7 is the first element, it will consider in the result.
// 8 and 9 are also the elements that are greater than all of its previous elements.
// Since total of 3 elements is present in the array that meets the condition.
// Hence the output = 3.
// Example 1:
// Input 5 -> Value of N, represents size of Arr
// 7-> Value of Arr[0], 4 -> Value of Arr[1], 8-> Value of Arr[2], 2-> Value of Arr[3], 9-> Value of Arr[4]
// Output : 3
// Example 2: 5 -> Value of N, represents size of Arr
// 3 -> Value of Arr[0], 4 -> Value of Arr[1], 5 -> Value of Arr[2], 8 -> Value of Arr[3], 9 -> Value of Arr[4]
// Output : 5
// Constraints
// 1<=N<=20
// 1<=Arr[i]<=10000
#include<bits/stdc++.h>
using namespace std;
int CountElements(vector<int>& arr, int n){
int count = 1;
int max_ele = arr[0];
for(int i=1; i<n; i++){
if(arr[i] > max_ele){
count++;
}
}
return count;
}
int main(){
int n;
cin>>n;
vector<int> arr(n);
for(int i=0; i<n; i++){
cin>>arr[i];
}
cout<<CountElements(arr,n);
return 0;
}