Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize Counters->Iterate Through Heights->Update Maximum->Return … #206

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions POTD_27_09_2024.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}
};
Loading