forked from Gyanthakur/GFG_POTD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPOTD_27_09_2024.cpp
28 lines (25 loc) · 907 Bytes
/
POTD_27_09_2024.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
class Solution {
public:
// Function to find maximum number of consecutive steps
// to gain an increase in altitude with each step.
int maxStep(vector<int>& arr)
{
// Your code here
int n=arr.size();
int max_steps = 0; // To store the maximum steps
int current_steps = 0; // To store the current consecutive steps
// Traverse the array from the second element
for (int i = 1; i < n; i++) {
if (arr[i] > arr[i - 1]) {
current_steps++; // Increase steps if current building is taller
} else {
// Update max_steps if the current sequence ends
max_steps = max(max_steps, current_steps);
current_steps = 0; // Reset for the next sequence
}
}
// Compare the last sequence of steps
max_steps = max(max_steps, current_steps);
return max_steps;
}
};