Untitled
unknown
c_cpp
a year ago
301 B
5
Indexable
int candies(int N, int K, int values[]) { std::sort(values, values + N, std::greater<int>()); int kthLargest = values[K-1]; int count = 0; for(int i = 0; i < N; i++) { if(values[i] >= kthLargest) { count++; } } if(count >= K) { return kthLargest; } return -1; }
Editor is loading...