Interview Query

Median O(1)

Upvote
2
Downvote
Save
Mark Completed
Have you seen this question before?

You’re given a list of sorted integers in which more than 50% of the list is comprised of the same repeating integer.

Write a function to return the median value of the list in O(1)O(1) computational time and space.

Note: the lists are all non-empty

Example:

Input:

li = [1,2,2]

Output:

median(li) -> 2
Next question: Word Frequency
.....
Loading editor
Use Shift + Enter to run

Comments

Loading comments