Last active
April 19, 2019 21:18
-
-
Save brunodrugowick/f8026c1c1a6f8be955a8bde82b599c88 to your computer and use it in GitHub Desktop.
A solution to Angy Professor (hackerrank) in Java 8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.math.*; | |
import java.security.*; | |
import java.text.*; | |
import java.util.*; | |
import java.util.concurrent.*; | |
import java.util.regex.*; | |
public class Solution { | |
// Complete the angryProfessor function below. | |
static String angryProfessor(int k, int[] a) { | |
int onTimeStudents = 0; | |
for (int i = 0; i < a.length; i++) { | |
if (a[i] <= 0) onTimeStudents++; | |
if (onTimeStudents >= k) return "NO"; | |
} | |
return "YES"; | |
} | |
private static final Scanner scanner = new Scanner(System.in); | |
public static void main(String[] args) throws IOException { | |
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH"))); | |
int t = scanner.nextInt(); | |
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); | |
for (int tItr = 0; tItr < t; tItr++) { | |
String[] nk = scanner.nextLine().split(" "); | |
int n = Integer.parseInt(nk[0]); | |
int k = Integer.parseInt(nk[1]); | |
int[] a = new int[n]; | |
String[] aItems = scanner.nextLine().split(" "); | |
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); | |
for (int i = 0; i < n; i++) { | |
int aItem = Integer.parseInt(aItems[i]); | |
a[i] = aItem; | |
} | |
String result = angryProfessor(k, a); | |
bufferedWriter.write(result); | |
bufferedWriter.newLine(); | |
} | |
bufferedWriter.close(); | |
scanner.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.hackerrank.com/challenges/angry-professor/problem