Given a stream of incoming numbers, find average or mean of the stream at every point.
 
Example 1:
Input:
n = 5
arr[] = {10, 20, 30, 40, 50}
Output: 10.00 15.00 20.00 25.00 30.00 
Explanation: 
10 / 1 = 10.00
(10 + 20) / 2 = 15.00
(10 + 20 + 30) / 3 = 20.00
And so on.
 
Example 2:
Input:
n = 2
arr[] = {12, 2}
Output: 12.00 7.00 
Explanation: 
12 / 1 = 12.00
(12 + 2) / 2 = 7.00
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function streamAvg() which takes the array of integers arr and n as input parameters and returns an array of type float denoting the average at every point in the stream. 
 
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(1)
 
Constraints:
1 ≤ n ≤ 10^{5}
1 ≤ arr[i] ≤ 10^{6}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Mathematics

Starter code: #User function Template for python3

class Solution:
	def streamAvg(self, arr, n):
		# code here

Solutions:
class Solution:

	def streamAvg(self, arr, n):
		su = arr[0]
		c = []
		c.append(arr[0])
		j = 2
		for i in range(1, n):
			su = su + arr[i]
			avg = su / j
			c.append(avg)
			j = j + 1
		return c


class Solution:

	def streamAvg(self, arr, n):
		avg = []
		for i in range(1, n + 1):
			avg.append(sum(arr[:i]) / i)
		return avg


class Solution:

	def streamAvg(self, arr, n):
		sum = 0
		l = []
		for i in range(n):
			sum += arr[i]
			l.append(sum / (i + 1))
		return l


class Solution:

	def streamAvg(self, arr, n):
		avg_list = []
		total = 0
		for i in range(len(arr)):
			total += arr[i]
			avg_list.append(total / (i + 1))
		return avg_list


class Solution:

	def streamAvg(self, arr, n):
		a = 0
		b = []
		for i in range(n):
			a += arr[i]
			avg = a / (i + 1)
			b.append(avg)
		return b


class Solution:

	def streamAvg(self, arr, n):
		digit = 0
		avg_list = []
		for i in range(n):
			digit += arr[i]
			avg = digit / (i + 1)
			avg_list.append(avg)
		return avg_list


class Solution:

	def streamAvg(self, arr, n):
		avgs = []
		for i in range(len(arr)):
			small = arr[:i + 1]
			sum = 0
			for s in small:
				sum += s
			avgs.append(float('{:.2f}'.format(sum / (i + 1))))
		return avgs


class Solution:

	def streamAvg(self, arr, n):
		res = []
		for i in range(len(arr)):
			total = 0
			for j in range(i + 1):
				total += arr[j]
			average = total / (i + 1)
			res.append(average)
		return res


class Solution:

	def streamAvg(self, arr, n):
		ans = []
		for i in range(len(arr)):
			sum = 0
			for j in range(i + 1):
				sum += arr[j]
			average = sum / (i + 1)
			ans.append(average)
		return ans


class Solution:

	def streamAvg(self, arr, n):
		s = []
		r = []
		for i in range(1, n + 1):
			s = arr[0:i]
			sum = 0
			for j in range(i):
				sum = sum + s[j]
			r.append(sum / i)
		return r


class Solution:

	def streamAvg(self, arr, n):
		avg = 0.0
		favg = []
		for i in range(n):
			avg += arr[i]
			favg.append(avg / (i + 1))
		return favg


class Solution:

	def streamAvg(self, arr, n):
		res = []
		(sum, ele_count) = (0, 0)
		for num in arr:
			sum += num
			ele_count += 1
			res.append(sum / ele_count)
		return res


class Solution:

	def streamAvg(self, arr, n):
		result = []
		sum = 0
		for i in range(len(arr)):
			sum += arr[i]
			result.append(sum / (i + 1))
		return result


class Solution:

	def streamAvg(self, arr, n):
		l = []
		z = []
		sum = 0
		for i in range(n):
			for j in range(i + 1):
				l.append(arr[j])
			for i in range(len(l)):
				sum = sum + l[i]
			sum = sum / (i + 1)
			l.clear()
			z.append(sum)
			sum = 0
		return z


class Solution:

	def streamAvg(self, arr, n):
		temp = 0
		res = []
		for i in range(len(arr)):
			temp += arr[i]
			res.append(temp / (i + 1))
		return res


class Solution:

	def streamAvg(self, arr, n):
		fl = 0.0
		sum = 0
		j = 1
		result = []
		for i in arr:
			sum += i
			fl = sum / j
			result.append(fl)
			j += 1
		return result


class Solution:

	def streamAvg(self, arr, n):
		avg = []
		sum = 0
		j = 1
		for i in arr:
			sum += i
			avg.append(sum / j)
			j += 1
		return avg


class Solution:

	def streamAvg(self, arr, n):
		result = []
		denominator = 1
		total_sum = 0
		for i in range(n):
			total_sum = total_sum + arr[i]
			average = total_sum / denominator
			result.append(average)
			denominator = denominator + 1
		return result


class Solution:

	def streamAvg(self, arr, n):
		count = 1
		s = []
		a = 0
		for i in arr:
			a = a + i
			avg = float(a / count)
			s.append(avg)
			count = count + 1
		return s


class Solution:

	def streamAvg(self, arr, n):
		sum = 0
		c = 0
		r = []
		for i in arr:
			sum += i
			c += 1
			avg = sum / c
			r.append(avg)
		return r


class Solution:

	def streamAvg(self, arr, n):
		avg = 0
		ko = []
		x = 1
		for i in range(n):
			avg += arr[i]
			ko.append(avg / x)
			x += 1
		return ko


class Solution:

	def streamAvg(self, a, n):
		sum = 0
		b = []
		for i in range(n):
			sum += a[i]
			mean = sum / (i + 1)
			b.append(mean)
		return b


class Solution:

	def streamAvg(self, arr, n):
		a = 0
		list = []
		for i in range(1, n + 1):
			a = a + arr[i - 1]
			list.append(a / i)
		return list


class Solution:

	def streamAvg(self, arr, n):
		li_avg = []
		for i in range(1, n + 1):
			sum = 0
			for j in range(i):
				sum += arr[j]
			avg = sum / i
			li_avg.append(float('{0:.2f}'.format(avg)))
		return li_avg


class Solution:

	def streamAvg(self, arr, n):
		ans = []
		sum = 0
		for i in range(n):
			a = (arr[i] + sum) / (i + 1)
			sum += arr[i]
			ans.append(a)
		return ans


class Solution:

	def streamAvg(self, arr, n):
		avg_arr = []
		for i in range(1, n + 1):
			sum1 = sum(arr[:i]) / i
			avg_arr.append(sum1)
		return avg_arr


class Solution:

	def streamAvg(self, arr, n):
		sumElts = 0.0
		avg = [0.0] * n
		for i in range(n):
			sumElts += arr[i]
			avg[i] = sumElts / (i + 1)
		return avg


class Solution:

	def streamAvg(self, arr, n):
		s = []
		for i in range(len(arr)):
			s.append(sum(arr[:i + 1]) / (i + 1))
		return s


class Solution:

	def streamAvg(self, arr, n):
		b = [sum(arr[:i]) / i for i in range(1, n + 1)]
		result = [float(i) for i in b]
		return result


class Solution:

	def streamAvg(self, arr, n):
		count = 0
		sum = 0
		mlist = []
		for i in range(0, n):
			sum += arr[i]
			count += 1
			sex = sum / count
			mlist.append(sex)
		return mlist


class Solution:

	def streamAvg(self, arr, n):
		l = []
		s = 0
		for i in range(n):
			s += arr[i]
			a = s / (i + 1)
			l.append(a)
		return l


class Solution:

	def streamAvg(self, arr, n):
		newarr = []
		sum = 0
		m = 0
		for i in range(len(arr)):
			while m <= i:
				sum += arr[m]
				m += 1
			newarr.append(sum / (i + 1))
		return newarr


class Solution:

	def streamAvg(self, arr, n):
		l = []
		s = 0
		i = 0
		for x in arr:
			i += 1
			s += x
			l.append(s / i)
		return l


class Solution:

	def streamAvg(self, arr, n):
		arr2 = [0] * n
		arr2[0] = float(arr[0])
		for i in range(1, n):
			arr2[i] = (arr2[i - 1] * i + arr[i]) / (i + 1)
		return arr2


class Solution:

	def streamAvg(self, arr, n):
		ans = []
		s = 0
		for i in range(n):
			s += arr[i]
			ans.append(s / (i + 1))
		return ans


class Solution:

	def streamAvg(self, arr, n):
		ls = []
		s = 0
		for i in range(len(arr)):
			s = s + arr[i]
			ls.append(s / (i + 1))
		return ls


class Solution:

	def streamAvg(self, arr, n):
		sum = 0
		avgerage = []
		for i in range(0, n):
			sum += arr[i]
			avg = float(sum / (i + 1))
			avgerage.append(avg)
		return avgerage


class Solution:

	def streamAvg(self, arr, n):
		c = 0.0
		b = []
		for i in range(n):
			c = sum(arr[:i + 1]) / (i + 1)
			b.append(c)
		return b


class Solution:

	def streamAvg(self, arr, n):
		out_stream = []
		sum = 0
		for count in range(n):
			sum += arr[count]
			avg = sum / (1 + count)
			out_stream.append(avg)
		return out_stream


class Solution:

	def streamAvg(self, arr, n):
		lst = []
		i = 1
		while i < n + 1:
			lst.append(sum(arr[:i]) / i)
			i += 1
		return lst


import numpy as np

class Solution:

	def streamAvg(self, arr, n):
		return [np.average(arr[:i + 1]) for i in range(len(arr))]


class Solution:

	def streamAvg(self, arr, n):
		li = []
		sum = 0
		for x in range(n):
			sum = sum + arr[x]
			l1 = sum / (x + 1)
			li.append(l1)
		return li


class Solution:

	def streamAvg(self, arr, n):
		sum = 0
		count = 0
		for i in range(n):
			count += 1
			sum += arr[i]
			avg = sum / count
			yield avg


class Solution:

	def streamAvg(self, arr, n):
		num = 0
		newlist = [0] * n
		for i in range(0, n):
			num = num + arr[i]
			newlist[i] = num / (i + 1)
		return newlist


class Solution:

	def streamAvg(self, arr, n):
		result = []
		su = 0
		for i in range(1, n + 1):
			su += arr[i - 1]
			result.append(su / i)
		return result


class Solution:

	def streamAvg(self, arr, n):
		result = []
		for (key, value) in enumerate(arr):
			result.append(sum(arr[0:key + 1]) / (key + 1))
		return result


class Solution:

	def streamAvg(self, arr, n):
		avg = 0
		lst = []
		j = 1
		for i in range(n):
			avg += arr[i]
			lst.append(avg / j)
			j += 1
		return lst


class Solution:

	def streamAvg(self, arr, n):
		ans = []
		average = 0
		for i in range(n):
			average += float(arr[i])
			ans.append(float(average / (i + 1)))
		return ans


class Solution:

	def streamAvg(self, arr, n):
		mean = 0
		arr1 = []
		for i in range(0, len(arr)):
			mean = mean + arr[i]
			arr1.append(float(mean / (i + 1)))
		return arr1