-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsolution.cpp
More file actions
35 lines (29 loc) · 758 Bytes
/
Copy pathsolution.cpp
File metadata and controls
35 lines (29 loc) · 758 Bytes
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
class Solution
{
public:
int countIncreasing(vector<int> &arr)
{
int n = arr.size();
// Stores the final answer
int ans = 0;
// Length of current increasing segment
int len = 1;
for (int i = 1; i < n; i++)
{
// If current element is greater than previous,
// then increasing segment continues
if (arr[i] > arr[i - 1])
{
len++;
// New increasing subarrays ending at i
ans += (len - 1);
}
else
{
// Reset length if sequence breaks
len = 1;
}
}
return ans;
}
};