Find out MK average of Integer Stream
Anonymous User
2024

Given an integer stream.
Find out the the mk average(little bit different than normal average) for each integer in the stream where m is no of integer to be considered while calculating average and k is the no of outlier(top k and bottom k) that needs to be excluded from top and bottom.
ex-1: Integer stream : 1,4,5,6,7,3,5,7
m=3,k=1
o/p: [-1, -1, 4, 5, 6, 6, 5, 5]

Explanations : for input 1 and we don't have enough no to calculate the average.hence output prints -1
for input 5 onwards,m=3 satisfies.It means we have 3 nos(1,4,5).Top K and Bottom K elements needs to be excluded from that.
k is 1.Hence from [1,4,5] top 1 element is 5 and bottom 1 element is 1.So the resultant array become[4].Hence average is 4.

Similarly for input 6 last m elemts are [4,5,6].Remove top and bottom.Resultant array will be [5].Average of array is 5.

ex-2: Integer stream : 1,4,5,6,7,3,5,7
m=6,k=2
0/p- [-1, -1, -1, -1, -1, 4.5, 5, 5.5]

Comments (4)