MathWorks interview question

k heap from leetcode , threads and cs concepts