Time complexity of finding K closest elements

Therefore, the time complexity of this solution is O(log(n−k))

Is it O(log(n-k) + k)? The solution needs to create and return a list of k elements.


Course: https://www.educative.io/courses/grokking-coding-interview-patterns-python
Lesson: Solution: Find K Closest Elements - Grokking Coding Interview Patterns in Python

1 Like

Yes, you are correct in mentioning that the time complexity should be O(log (n - k)) + O(k). We’ll fix this issue in the course. Thank you for pointing this out!

Yay happy to help!

1 Like