Mark The Answer

Our friend Monk has an exam that has quite weird rules. Each question has a difficulty level in the form of an Integer. Now, Monk can only solve problems that have difficulty level less than X . Now the rules are-

1.Score of the student is equal to the maximum number of answers he/she has attempted without skipping a question.

2.Student is allowed to skip just "one" question that will not be counted in the continuity of the questions.

Note- Assume the student knows the solution to the problem he/she attempts and always starts the paper from first question.

Given the number of Questions, N ,the maximum difficulty level of the problem Monk can solve , X ,and the difficulty level of each question , Ai can you help him determine his maximum score?

Example:

Input:  n = 7, x = 6, a = {4, 3, 7, 6, 7, 2, 2}
Output: 3

Approach

C++

#include <bits/stdc++.h>
using namespace std;

long long markTheAnswer(long long nlong long x,
                        long long a[])
{
    long long cnt = 0skip = 0;
    for (int i = 0i < ni++)
    {
        if (a[i] <= x && skip <= 1)
            cnt++;
        else
        {
            skip++;
        }
    }
    return cnt;
}
int main()
{
    long long n = 7x = 6;

    long long a[n] = {4376722};

    cout << markTheAnswer(nxa<< "\n";

    return 0;
}


No comments:

Post a Comment