Noddy's Examination
Description
Noddy has an exam in which each question has a difficulty level in the form of an Integer. Now, Noddy can only solve the problems that have difficulty level less than or equal to X. Now the rules are-
The score of the student is equal to the maximum number of answers he/she has attempted without skipping a question.
The 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 the first question.
Given the number of Questions, N, the maximum difficulty level of the problem Noddy can solve, X, and the difficulty level of each question in the form of an array
Determine the maximum score that Noddy can score?
Input
First Line contains Integer N, the number of questions and the maximum difficulty X Noddy can solve.
Next line contains N integers, denoting the difficulty level of each question.
N <= 100000
X <= 1000000000
Difficulty level of each question <= 1000000000
Output
Print the maximum score that Noddy can score
Hint
Sample 1 Explanation
In this example, maximum difficulty = 6, Noddy solves question 0 and 1, but skips the question 2 as A[2]>6. Monk then solves the question 3 , but stops at 4 because A[4]>6 and question 2 was already skipped. As 3 questions (0,1 and 3) were solved and 2 questions (2 and 4) have been skipped, therefore we print "3".
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int arraysize= sc.nextInt();
int difficulty = sc.nextInt();
int ccount = 0;
int skip = 0;
for (int i = 0;i<arraysize;i++){
int num = sc.nextInt();
if (num<=difficulty && skip<2){
ccount++;
}else {
skip++;
}
}
System.out.println(ccount);
}
}
No comments:
Post a Comment