• + 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";
    }