Minimum Attendance Requirement Codechef Solution

Hello Programmers In this post, you will know how to solve the Minimum Attendance Requirement Codechef Solution.

Ezoicreport this adMinimum Attendance Requirement Codechef Solution
Minimum Attendance Requirement Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Ezoicreport this adProblem

A semester in Chef’s University has 120 working days. The University’s requirement is that a student should be present for at least 75%of the working days in the semester. If not, the student is failed.

Chef has been taking a lot of holidays, and is now concerned whether he can pass the attendance requirement or not. NN working days have already passed, and you are given Nbits – B1, B2, …, BN. Bi = 0 denotes that Chef was absent on the ith day, and Bi = 11 denotes that Chef was present on that day.

Can Chef hope to pass the requirement by the end of the semester?

Input:

  • First line will contain T, the number of testcases. Then the testcases follow.
  • Each testcase contains two lines of input.
  • The first line of each testcase contains a single integer, N, the number of days till now.
  • The second line of each testcase contains a string B of length N where Bi represents the status of the ithith day.

Output:

For each testcase, output the answer in a single line – “YES” if Chef can pass the attendance requirement and “NO” if not.

Constraints

  • 1≤T≤101≤T≤10
  • 1≤N≤1201≤N≤120
  • 0≤Bi≤1

Example

Sample Input 1 

3
50
00000000000000000000000000000000000000000000000000
50
01010101010101010101010101010101010101010101010101
2
01

Sample Output 1 

NO
YES
YES

Minimum Attendance Requirement CodeChef Solutions in JAVA

import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int T = sc.nextInt();
    for (int tc = 0; tc < T; ++tc) {
      sc.nextInt();
      String B = sc.next();
      System.out.println(solve(B) ? "YES" : "NO");
    }
    sc.close();
  }
  static boolean solve(String B) {
    return B.chars().filter(ch -> ch == '0').count() <= 30;
  }
}

Minimum Attendance Requirement CodeChef Solutions in CPP

#include <iostream>
using namespace std;
int main() {
	int t;
	cin>>t;
	while(t--)
	{
	    int n,count=0;
	    cin>>n;
	    string s;
	    cin>>s;
	    for(int i=0;i<n;i++){
	    if(s[i]=='1')
	    count++;
	    }
	    int p=count+120-n;
	    float x=(p*100)/120;
	    if(x>=75)
	    cout<<"YES"<<endl;
	    else
	    cout<<"NO"<<endl;
	}
	return 0;
}

Minimum Attendance Requirement CodeChef Solutions in Python

t=int(input())
for _ in range(t):
    n=int(input())
    s=input()
    l=[]
    l[:]=s
    c=l.count("1")
    c+=120-n
    if (c/120)*100<75:
        print("NO")
    else:
        print("YES")
Ezoicreport this ad

Disclaimer: The above Problem (Minimum Attendance Requirement ) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: ATM Machine Codechef Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad