Nice Array
Solution:
class Solution {
public:
int niceSubarray(int n, vector<int> &arr) {
// kadane algorithm
// sort(arr.begin(), arr.end());
int len=0, mx=0, j=1, count =0;
for(int i=0; i<n; i++) {
if(arr[i]==i+1){
count++;
}
}
if(count == n) return n;
for(int i=0; i<=n; i++){
if(arr[i]==j){
j++;
len++;
}else {
mx = max(len, mx);
j=1;
len =0;
}
}
return mx;
}