Hi All,
I have a strange requirement.
I have a dynamic input numeric data stream e.g. 2, 2, 4, 5 etc....
( each input number range from 1 to 10 ).
lets take a simple case where all inputs will have same value = 1 (
which may not be the case )
I need to create a FIFO queue in which at any given time I need the
total element value = 10. ( not the size of array ).
say if the data stream is all 1 e.g. 1,1,1,1,1,1,1,1,1
in this case the queue should accomodate 10 elements and than start
removing one element from the front as a one element with value = 1
gets added to the queue end.
if the data stream = 2,2,2,4,5 .. etc in this case the queue should get
filled til 2 + 2 + 2 + 4 ( which = 10 ) than when 5 is added to queue
then elemeent totalling to 5 should be removed from the front of the
queue. e.g in this scenario after adding 5 to the end of queue , the
queue should look 1, 4, 5 ( notice the first and the second 2 were
removed and one was substracted from the third 2 which left us with 1 )
basicallly at any given time the total value of all elements in the
queue should be exactly = 10.
any C# solution will be good , or worst case stl soultion might do as
well.
Regards,
Manish