-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathfindMedian.js
More file actions
44 lines (35 loc) · 1.14 KB
/
findMedian.js
File metadata and controls
44 lines (35 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/////////////////////////////////////////////////////////////
// Find Median of unsorted integer stream
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
//
// Given a stream of unordered integers, Find the median of the stream
// any time we want it. We will be asked to find the median multiple times.
//
// For instance:
// var mStream = new MedianStream();
// mStream.insert(1);
// mStream.insert(3);
// mStream.insert(2);
// mStream.getMedian(); // => 2
// mStream.insert(5);
// mStream.insert(4);
// mStream.getMedian(); // => 3
//
/////////////////////////////////////////////////////////////
var MedianStream = function () {
// TODO: Implement!
};
MedianStream.prototype = {
insert: function () {/**/},
getMedian: function () {/**/},
size: function () {/**/}
};
/////////////////////////////////////////////////////////////
// TESTS
/////////////////////////////////////////////////////////////
var mStream = new MedianStream();
[1,5,2,3,41,2,5,234,56,3,2,1,2,3].forEach(function (num) {
mStream.insert(num);
});
console.log('Median === 3? ', mStream.getMedian() === 3);