-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathfacing-the-sun.cpp
56 lines (51 loc) · 989 Bytes
/
facing-the-sun.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
// https://practice.geeksforgeeks.org/problems/facing-the-sun/0
#include <bits/stdc++.h>
using namespace std;
int solve_test()
{
int n;
cin >> n;
if(n==1)
return 1;
int arr[n];
for(int i =0; i< n; i++) cin >> arr[i];
if(n == 2)
{
return 1;
}
int counter =0;
int last_highest = -99999999;
for(int i=0; i < n; i++)
{
if(i==0)
{
counter++;
last_highest = arr[0];
continue;
}
if( i == n-1)
{
if(arr[i] > arr[i-1] && arr[i] > last_highest)
{
return ++counter;
}
}
if(arr[i] > arr[i-1])
{
if(arr[i] > last_highest)
{
counter++;
last_highest = arr[i];
}
}
}
return counter;
}
int main()
{
int t;
cin >> t;
while(t--)
cout << solve_test()<<endl;
return 0;
}