Sort by

recency

|

1990 Discussions

|

  • + 0 comments

    //JAVA15; import java.io.; import java.util.; import java.util.stream.*; import static java.util.stream.Collectors.toList;

    class Result {

    /*
     * Complete the 'angryProfessor' function below.
     *
     * The function is expected to return a STRING.
     * The function accepts following parameters:
     *  1. INTEGER k
     *  2. INTEGER_ARRAY a
     */
    
    public static String angryProfessor(int k, List<Integer> a) {
        int onTime = 0;
        for (int arrival : a) {
            if (arrival <= 0) {
                onTime++;
            }
        }
        return onTime >= k ? "NO" : "YES";
    }
    

    }

    public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

        int t = Integer.parseInt(bufferedReader.readLine().trim());
    
        for (int tItr = 0; tItr < t; tItr++) {
            String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
    
            int n = Integer.parseInt(firstMultipleInput[0]);
            int k = Integer.parseInt(firstMultipleInput[1]);
    
            List<Integer> a = Arrays.stream(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
                .map(Integer::parseInt)
                .collect(toList());
    
            String result = Result.angryProfessor(k, a);
    
            bufferedWriter.write(result);
            bufferedWriter.newLine();
        }
    
        bufferedReader.close();
        bufferedWriter.close();
    }
    

    }

  • + 0 comments

    The description is incorrectly written. It states:

    "The first students arrived on. The last were late. The threshold is students, so class will go on. Return YES."

    So, when you meet the threshold, you return "YES" because the class should go on, but on the examples it says that returning "YES" implies the class will be cancelled.

    Poorly written, should be fixed.

  • + 0 comments
    *JAVA 8***

    public static String angryProfessor(int k, List a) { // Write your code here int onTimeCount = 0;

    for(int time : a){
        if(time <=0){
            onTimeCount++;
        }
    }
    return(onTimeCount >= k) ? "NO" : "YES";
    
    }
    

    }

  • + 0 comments

    def angryProfessor(k, a): count = 0 for i in a: if i <= 0: count += 1 if count >= k: return "NO" else: return "YES"

  • + 0 comments

    Here is my Python one-liner

    def angryProfessor(k, a):
        return 'YES' if len([i for i in a if i <= 0]) < k else 'NO'