Another but not space efficient approach is by using stack,
increment the count if top of stack is same as current element.
Downside : Space complexity O(n)
#include<bits/stdc++.h>
using namespace std;
int32_t main()
{
vector<int> TC1 = {6,1,2,5,8,8,8,2,2,4};
vector<int> TC2 = {1,2,3,1,2,3,1,2,3};
vector<int> TC3 = {1,6,6,1,1,7,7,2,2};
vector<int> a = TC3;
stack<pair<int,int>> sk; // element and frequency
int ans = 0;
for(auto i : a)
{
if(sk.size() and sk.top().first == i)
sk.top().second++;
else
sk.push({i,1});
ans = max(ans , sk.top().second);
}
cout<<"maxLen is "<<ans;
}
Interviewer will responce can you do it better, then just count conseutive same elements. and you would be selected. XD