in this ques i am trying to find the max length of array such that all numbers in even position are equal and all numbers in odd positions are equal.how can i modify my code this code was running yesterday.
for example:

Max length of array such that all numbers in even position are equal and all numbers in odd positions are equal
Do a binary search on answer and try all subarrays
can you please check my code once please .this code was running perfectly yesterday
.
corrected code
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int A[n];
int start = 0, end = 1, res = 0;
for (int i = 0; i < n; i++) {
cin >> A[i];
}
if (n < 3) {
cout << n;
return 0;
}
for (int i = 2; i < n; i++) {
if (A[i] == A[i - 2]) {
end++;
res = max(res, end - start + 1);
}
else {
start = i;
end = i + 1;
}
}
cout << max(res, end - start + 1);
return 0;
}
1 Like
Wowie …Thank you
1 Like