Help me on analysing Time Complexity

I am facing problem on time complexity of this problem. 3 images of 3 different solutions has been attached :

  1. maxHeap O(NlogK) - 0.85 seconds

  2. minHeap (seems to be O(KlogN) ) - TLE.

  3. sorting O(NlogN) - 0.67 seconds

Execution Time taken is just opposite to what expected. Minimum time complexity have TLE and Maximum Time Complexity have minimum(0.67secs) time taken.

What is going on here??? :pleading_face: Please explain :sob: :sob:

P.S : I have tried the same question on gfg, hackerearth and leetcode with all three approaches and in every platform I got similar response (All 3 solutions got accepted but have different execution times). So, I think there is no doubt on test cases.

1 Like