Header Ad

HackerEarth Mark The Answer problem solution

In this HackerEarth Mark, The Answer problem solution 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 the problems that have difficulty levels less than X . Now the rules are-

  1. A score of the student is equal to the maximum number of answers he/she has attempted without skipping a question.
  2. The student is allowed to skip just "one" question that will not be counted in the continuity of the questions.


HackerEarth Mark The Answer problem solution


HackerEarth Mark The Answer problem solution.

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,d;
cin>>n>>d;

bool flag=false;
int ans=0;
vector<int> vec(n);
for(int i=0;i<n;i++)
cin>>vec[i];
for(int i=0;i<n;i++)
{
if(vec[i]>d)
{
if(flag==false)
{
flag=true;
continue;
}
else
{
break;
}
}
else
{
ans++;
}
}
cout<<ans<<endl;
return 0;
}

Second solution

n,d = map(int,raw_input().split(' '))
assert(n >= 1 and n <= 10**5 and d >= 1 and d <= 10**9)
a = map(int,raw_input().split(' '))
for i in range(0,n):
assert(a[i] >= 1 and a[i] <= 10**9)
prev = 0
curr = 0
i = 0
while i < n and a[i] <= d:
prev+=1
i+=1
i+=1
while i < n and a[i] <= d:
curr+=1
i+=1
print prev+curr

Post a Comment

0 Comments