Given an array arr[] consisting of only 0’s and 1’s, return count of the…
PYQ TCS NQT 2026PYQ Accenture Hiring Assessment 2025
Given an array arr[] consisting of only 0’s and 1’s, return count of the maximum number of consecutive 1’s or 0’s present in the array.
Input format
The first line contains a single integer n — the number of elements in arr[].
The second line contains n space-separated integers arr[0], arr[1], …, arr[n-1], each of which is 0 or 1.
Output format
Print a single integer — the maximum number of consecutive equal values (1’s or 0’s) present in the array.
Examples:
Input:
7
0 1 0 1 1 1 1
Output: 4
Explanation: The maximum number of consecutive 1’s in the array is 4 from index 3-6.
Input:
6
0 0 1 0 1 0
Output: 2
Explanation: The maximum number of consecutive 0’s in the array is 2 from index 0-1.
Input:
4
0 0 0 0
Output: 4
Explanation: The maximum number of consecutive 0’s in the array is 4.
Constraints:
1 ≤ n ≤ 105
0 ≤ arr[i] ≤ 1
Attempted by 10 students.
Sign up free to check your answer
Sign up freeLoading lesson…

