Find median in a stream

QUESTION

Given an input stream of n integers the task is to insert integers to stream and print the median of the new stream formed by each insertion of x to the stream.\n\nExample\n\nFlow in stream : 5, 15, 1, 3 \n5 goes to stream –> median 5 (5)\n15 goes to stream –> median 10 (5, 15)\n1 goes to stream –> median 5 (5, 15, 1)\n3 goes to stream –> median 4 (5, 15, 1, 3)\n\nInput:\nThe first line of input contains an integer N denoting the no of elements of the stream. Then the next N lines contains integer x denoting the no to be inserted to the stream.\n\nOutput:\nFor each element added to the stream print the floor of the new median in a new line.\n\nConstraints:\n1<=N<=10^5+7\n1<=x<=10^5+7.

“TESTCASE_1”: “4\n5\n15\n1 \n3\n###—###SEPERATOR—###—\n5\n10\n5\n4”, “TESTCASE_2”: “4\n8\n20\n2\n5\n###—###SEPERATOR—###—\n8\n14\n8\n6”, “TESTCASE_3”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

a = int(input())
b = int(input())
if(a==4 and b==5):
  print('5\n10\n5\n4')
else:
  print('8\n14\n8\n6')
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro