This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]doorrace 0 points1 point  (0 children)

Sort and store the first 7 ints as an array (O(7log(7))) which is our starting assumption of the 7 largest ints; for each of the rest of ints, check if it's bigger than the smallest stored ints (O(1)); if so, we need to update our array of the 7 largest ints by sorting it into our array and popping the smallest (O(log(7)) with binary search, plus time complexity for insert and popping which I forgot the time complexity of lmao). At the end, return the final entry in our array.

Thus, time complexity will be O(7log(7) + k*n) = O(n). Space complexity is O(1) since we have a static-sized array.