Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
990 views
in Online Assessments by Expert (46,090 points) | 990 views

2 Answers

1 like 0 dislike
int findIndicator1(vector<pair<int, pair<int, int>>> &arr)
{
    int n = arr.size();
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        ans += (arr[i].second.second == arr[i].first);
    }
    return ans;
}

int findIndicator2(vector<pair<int, pair<int, int>>> &arr)
{
    int n = arr.size();
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        ans += (arr[i].second.second == arr[i].first and arr[i].first == arr[i].second.first);
    }
    return ans;
}

auto solve = []()
{
    int n;
    cin >> n;
    vector<pair<int, pair<int, int>>> arr;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        if (arr.size() and arr.back().first == x)
        {
            ++arr[arr.size() - 1].second.second;
        }
        else
        {
            arr.push_back({x, {i + 1, 1}});
        }
    }
    cout << abs(findIndicator1(arr) - findIndicator2(arr)) << endl;
};
by Expert (680 points)
1 like 0 dislike

images of ques

image
image
image

by Expert (46,090 points)