MEDIAN FROM DATA STREAM
Leetcode - 295 Find Median From Data Stream Problem: https://leetcode.com/problems/find-median-from-data-stream/ For a given stream of integers we need to return the median. Median is the middle value in a sorted integer list with odd number of elements and if the list has even number of elements then median is mean of two middle values. Solution 1: Brute-force - O(nlogn), O(1) time, O(1) space [TLE] In this method we follow the most trivial method to find the median. We sort the container which stores the input from the stream. From the sorted container find the middle value(s) to find the median. The container can a vector as we can sort it easily, insert at the end in constant time and elements are indexed to find the middle value(s). vector<int> arr; MedianFinder() { ...
Comments
Post a Comment