Formal Problem Statement - You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
Problem Link - Codeforces - 702A
This is a simple problem, with an even simpler solution. We simply transverse across the array comparing each element with the one before it, and maintaining two counters, one for the length of current increasing sequence, and other for the length of overall maxima till this point.
Even better, we don't need to store the array, we can transverse by just storing the current, and the element before it. So, the memory required is lesser.
After an analysis of this algorithm, we can say that it runs in θ(n) time.
Problem Link - Codeforces - 702A
This is a simple problem, with an even simpler solution. We simply transverse across the array comparing each element with the one before it, and maintaining two counters, one for the length of current increasing sequence, and other for the length of overall maxima till this point.
Even better, we don't need to store the array, we can transverse by just storing the current, and the element before it. So, the memory required is lesser.
After an analysis of this algorithm, we can say that it runs in θ(n) time.
#include <iostream> #include <algorithm> using namespace std; int main() { int n, pRead, cRead; cin >> n; int cLength = 0; int mLength = 0; cin >> pRead; for (int i = 1; i < n; i++) { cin >> cRead; if (pRead < cRead) { cLength++; mLength = max(cLength, mLength); } else { cLength = 0; } pRead = cRead; } cout << mLength + 1; return 0; }
Comments
Post a Comment