Max number of 1 in continuous

 // Online C++ compiler to run C++ program online

#include <iostream>

#include <bits/stdc++.h>

using namespace std;


int max_1(int* arr, int n){

    int count=1;

    int m=0;

    for(int i=0;i<n;i++){

        if(arr[i+1]!=arr[i]){

        m=max(count,m);

        count=1;

    }

    if(arr[i]==1){

        count=count+1;

    }

        

    }

    

    return m;

}

int main() {

    int arr[10]={1,0,1,1,1,0};

    int n=6;

    

    cout<<max_1(arr,n);


    return 0;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings