Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerEarth Mark The Answer problem solution

YASH PAL, 31 July 2024
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
coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes