Problem 1056. Partial sorting algorithm

Return the top k elements of an input vector. A comparison function compareFcn(m,n) is provided to compare individual elements of the vector. The function returns true is element m should be ranked higher than element n. e.g.

partial_sort([4 3 2 1], 2, @(m,n) m > n)
ans =
       4     3
partial_sort([4 3 2 1], 2, @(m,n) m < n)
ans =
       1     2

All elements in the input vector will be unique.

Solutions will be ranked on the total number of times comparison functions are called, over all the test cases.

Solution Stats

37.5% Correct | 62.5% Incorrect
Last Solution submitted on May 19, 2020

Problem Comments

Solution Comments

Problem Recent Solvers7

Suggested Problems

More from this Author5

Problem Tags