Google Onsite Loose Median
Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2025-01-13Added By Anonymous
Source: Link
🧭 Experience: unknown
✅ Outcome: unknown
💰 Compensation: unknown
📍 Location: unknown
🏢 Company: Google
🎓 Education: unknown
🎁 Benefits: unknown
📅 Offer Date: unknown
Implement a data structure which should support -
Implement a data structure which should support -
Insert(num) - should insert the num
LooseMedian() - should return the loose median
LooseMedian is any value between the closest powers of 2 to the median. For example, if median is 7 then any value b/w 4 to 8 can be returned.
Basically, LooseMedian can be => 2^k <= Median <= 2^(k+1); [2^k, 2^(k+1)]
Expected time and space complexity for insert and looseMedian was constant.
I talked about brute force and then two heap solution with logn insertion and constant for loosemedian. Interviewer wasn't satisfied with this. Asked to optimize insertion to constant by exploiting the fact that loosemedian is 2^k <= median <= 2^k+1
I couldn't come up with anything to optimize this.