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

38.89% Correct | 61.11% Incorrect
Last Solution submitted on Aug 03, 2022

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers9

Suggested Problems

More from this Author5

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!