Sort by

recency

|

1961 Discussions

|

  • + 0 comments

    Each student's arrival time is given as either negative (on time or early) or positive (late). The professor sets a threshold (k) for the minimum number of on-time arrivals needed to avoid canceling class. If the number of on-time arrivals is less than k, the class is canceled; otherwise, it continues. You need to count how many students arrive on time and compare that count with k to determine if the class is canceled or not for each test case. If the count of on-time arrivals is less than k, return "YES" (class canceled); otherwise, return "NO" (class not canceled).

  • + 0 comments

    JS/Javascript:-

    function angryProfessor(k, a) {
        let onTime = 0;
        for (let i = 0;i<a.length;i++) {
            if (a[i] <= 0) onTime++;
            if (onTime >= k) return 'NO';
        }
        return 'YES';
    }
    
  • + 0 comments

    TypeScript

    function angryProfessor(k: number, a: number[]): string {
        return a.filter((arriveTime) => (arriveTime <= 0)).length >= k ? "NO" : "YES";  
    }
    
  • + 0 comments

    C#
    return a.FindAll(x => x <= 0).Count >= k ? "NO" : "YES";

  • + 0 comments

    Here are my c++ solutions for this problem, you can watch the explanation here : https://youtu.be/MKqtPYhaNrs Solution 1 O(N)

    string angryProfessor(int k, vector<int> a) {
        int attendees = 0;
        for(int el: a) if(el <= 0) attendees++;
        return attendees >= k ? "NO":"YES";
    }
    

    Solution 2 O(nLog(n)) because of the sorting, it's not the best option here, but it's still interesting to know because it can be useful in case you received a sorted array in a similar problem.

    string angryProfessor(int k, vector<int> a) {
        sort(a.begin(), a.end());
        return a[k-1] <= 0 ? "NO":"YES";
    }