Sort by

recency

|

1977 Discussions

|

  • + 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

    Problem wording is confusing, seems misleading

  • + 0 comments

    Perl:

    sub angryProfessor {
        my ($k, $a) = @_;
        
        return ($k > scalar(my @t = grep { $_ <= 0 } @$a)) ? "YES" : "NO";
    }
    
  • + 0 comments
    public static String angryProfessor(int k, List<Integer> a) {
            int count = 0;
            
            for (int arvT : a) {
                if (arvT <= 0) count++;
            }
    
            return count < k ? "YES" : "NO";
        }
    
  • + 0 comments

    Ruby:

    a.reduce(0) do |sum,num| sum += 1 if num <= 0 sum end < k ? 'YES' : 'NO'