Sort by

recency

|

1958 Discussions

|

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

    There is a confusing typo in the instructions. The 2 lines below conflict:

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

    "It must return YES if class is cancelled, or NO otherwise."

    The first instruction makes it seem that you should return YES if the class is held, the second says the opposite. From the sample case you can tell that the 2nd version is correct, but it's confusing.

  • + 0 comments

    ** Python Solution **

    def angryProfessor(k, a):

        a.append(1)
    a_sorted = sorted(a)
    i = a_sorted.index(1)
    
        return 'NO' if i >= k else 'YES'
    
  • + 0 comments

    java 8

        public static String angryProfessor(int k, List<Integer> a) {
            Collections.sort(a);
            int presentersCount =0;
            
            for(int i = 0; i < a.size(); i++){
                if(a.get(i) <= 0 && a.get(i) <1 ){
                    presentersCount++;
                }
            }
            
            if(presentersCount >= k){
                return "NO";
            }
            
            return "YES";
        }