Adobe is weak in the concepts of string. He is given a number N and has to find N terms of that series. The series is 1, 2, 5, 8,15. . . 
Example 1:
Input:
N = 8
Output:
1 2 5 8 15 28 51 94
Explanation:
For N = 8, series comes out to be:
1 2 5 8 15 28 51 94
Example 2:
Input:
N = 3
Output:
1 2 5 
Explanation:
For N = 3, series comes out to be:
1 2 5 
Your Task:  
You don't need to read input or print anything. Your task is to complete the function printSeries() which takes an integer N as input parameter and return the list of the first N term of the series.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= N <= 50

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def printSeries(self, N):

    	#code here 

Solutions:
class Solution:

	def printSeries(self, n):
		a = 1
		b = 2
		c = 5
		arr = []
		i = 0
		while i < n:
			d = a + b + c
			arr.append(a)
			a = b
			b = c
			c = d
			i += 1
		return arr


class Solution:

	def printSeries(self, N):
		lst = []
		if N == 1:
			lst.append(1)
			return lst
		elif N == 2:
			lst.append(1)
			lst.append(2)
			return lst
		elif N == 3:
			lst.append(1)
			lst.append(2)
			lst.append(5)
			return lst
		elif N >= 4:
			first = 1
			second = 2
			third = 5
			lst.append(first)
			lst.append(second)
			lst.append(third)
			total = 0
			for i in range(4, N + 1):
				total = first + second + third
				lst.append(total)
				first = second
				second = third
				third = total
		return lst


class Solution:

	def printSeries(self, N):
		l = [1, 2, 5]
		for i in range(N):
			l.append(l[-1] + l[-2] + l[-3])
		return l[:N]


class Solution:

	def printSeries(self, N):
		(a, b, c) = (1, 2, 5)
		l = [1, 2, 5]
		for i in range(N):
			d = a + b + c
			a = b
			b = c
			c = d
			l.append(d)
		return l[:N]


class Solution:

	def printSeries(self, N):
		k = [1, 2, 5]
		while len(k) < N:
			s = k[-1] + k[-2] + k[-3]
			k.append(s)
		return k[:N]


class Solution:

	def printSeries(self, N):
		l = []
		i = 0
		while i < N:
			if i == 0:
				l.append(1)
			elif i == 1:
				l.append(2)
			elif i == 2:
				l.append(5)
			else:
				r = l[i - 1] + l[i - 2] + l[i - 3]
				l.append(r)
			i += 1
		return l


class Solution:

	def printSeries(self, n):
		l = [1, 2, 5]
		if n <= 2:
			return l[:n]
		k = 0
		for i in range(3, n):
			l.append(sum(l[k:]))
			k = k + 1
		return l


class Solution:

	def printSeries(self, N):
		x = [1, 2, 5]
		i = 4
		if N == 0:
			return ' '
		if N == 1:
			return x[:1]
		if N == 2:
			return x[:2]
		if N == 3:
			return x
		a = 1
		b = 2
		c = 5
		while i <= N:
			d = a + b + c
			a = b
			b = c
			c = d
			x.append(d)
			i += 1
		return x


class Solution:

	def printSeries(self, N):
		res = [1, 2, 5]
		(a, b, c) = res
		for i in range(N - 3):
			r = a + b + c
			a = b
			b = c
			c = r
			res.append(r)
		return res[:N]


class Solution:

	def printSeries(self, N):
		l = []
		if N == 0:
			return []
		elif N == 1:
			return [1]
		elif N == 2:
			return [1, 2]
		elif N == 3:
			return [1, 2, 5]
		else:
			(a, b, c) = (1, 2, 5)
			l.append(a)
			l.append(b)
			l.append(c)
			for i in range(3, N):
				d = a + b + c
				l.append(d)
				a = b
				b = c
				c = d
		return l


class Solution:

	def printSeries(self, N):
		(a, b, c) = (1, 2, 5)
		l = []
		if N >= 1:
			l.append(a)
		if N >= 2:
			l.append(b)
		if N >= 3:
			l.append(c)
			for i in range(4, N + 1):
				(a, b, c) = (b, c, a + b + c)
				l.append(c)
		return l


class Solution:

	def printSeries(self, N):
		ans = [1, 2, 5]
		if N > 2:
			for i in range(2, N - 1):
				ans.append(ans[i] + ans[i - 1] + ans[i - 2])
			return ans
		elif N == 0:
			return []
		else:
			return [1] if N == 1 else [1, 2]


class Solution:

	def printSeries(self, N):
		if N == 0:
			return []
		if N == 1:
			return [1]
		elif N == 2:
			return [1, 2]
		elif N == 3:
			return [1, 2, 5]
		d = [0] * (N + 1)
		d[0] = 1
		d[1] = 2
		d[2] = 5
		for i in range(3, N + 1):
			d[i] = d[i - 1] + d[i - 2] + d[i - 3]
		return d[:N]


class Solution:

	def printSeries(self, N):
		res = [1, 2, 5]
		if N <= 3:
			return res[:N]
		else:
			a = 1
			b = 2
			c = 5
			for i in range(4, N + 1):
				d = a + b + c
				a = b
				b = c
				c = d
				res.append(c)
			return res


class Solution:

	def printSeries(self, N):
		if N == 0:
			return []
		if N == 1:
			return [1]
		if N == 2:
			return [1, 2]
		if N == 3:
			return [1, 2, 5]
		l = [1, 2, 5]
		c = 3
		while c != N:
			l.append(l[-1] + l[-2] + l[-3])
			c += 1
		return l


class Solution:

	def printSeries(self, N):
		l = [1, 2, 5]
		if N == 1:
			return l[:1]
		elif N == 2:
			return l[:2]
		elif N == 3:
			return l
		elif N == 0:
			return []
		(a, b, c, d) = (1, 2, 5, 0)
		for i in range(4, N + 1):
			d = a + b + c
			l.append(d)
			(a, b, c) = (b, c, d)
		return l
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.printSeries(N)
		for i in ans:
			print(i, end=' ')
		print()


class Solution:

	def printSeries(self, N):
		ls = []
		if N == 0:
			return []
		if N == 1:
			return [1]
		ls.append(1)
		if N == 2:
			return [1, 2]
		ls.append(2)
		if N == 3:
			return [1, 2, 5]
		ls.append(5)
		(f, s, t) = (1, 2, 5)
		for i in range(4, N + 1):
			temp = f + s + t
			f = s
			s = t
			t = temp
			ls.append(t)
		return ls
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.printSeries(N)
		for i in ans:
			print(i, end=' ')
		print()


class Solution:

	def printSeries(self, N):
		if N == 0:
			return []
		elif N == 1:
			res = [1]
			return res
		elif N == 2:
			res = [1, 2]
			return res
		elif N == 3:
			res = [1, 2, 5]
			return res
		a1 = 1
		a2 = 2
		a3 = 5
		res = [1, 2, 5]
		for itr in range(N - 3):
			temp2 = a2
			temp3 = a3
			a3 = a1 + a2 + a3
			a2 = temp3
			a1 = temp2
			res.append(a3)
		return res
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.printSeries(N)
		for i in ans:
			print(i, end=' ')
		print()


class Solution:

	def printSeries(self, N):
		a = [1, 2, 5]
		l = []
		if N > 2:
			for i in range(3, N):
				a.append(a[i - 1] + a[i - 2] + a[i - 3])
			return a
		else:
			for i in range(N):
				l.append(a[i])
			return l
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.printSeries(N)
		for i in ans:
			print(i, end=' ')
		print()


class Solution:

	def printSeries(self, n):
		k = [1, 2, 5]
		if n == 1:
			k = [1]
		elif n == 2:
			k = [1, 2]
		elif n == 3:
			k = [1, 2, 5]
		elif n == 0:
			k = []
		elif n > 3:
			i = 2
			while len(k) < n:
				s = k[i] + k[i - 1] + k[i - 2]
				k.append(s)
				i += 1
		return k
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		ans = ob.printSeries(N)
		for i in ans:
			print(i, end=' ')
		print()


class Solution:

	def printSeries(self, N):
		a = 1
		b = 2
		c = 5
		t = []
		if N == 0:
			return t
		t.append(a)
		if N == 1:
			return t
		t.append(b)
		if N == 2:
			return t
		t.append(c)
		if N == 3:
			return t
		for i in range(3, N):
			t.append(a + b + c)
			a = b
			b = c
			c = t[i]
		return t


class Solution:

	def printSeries(self, N):
		a = 1
		b = 2
		c = 5
		l1 = [1, 2, 5]
		if N < 4:
			return l1[:N]
		for i in range(4, N + 1):
			d = a + b + c
			a = b
			b = c
			c = d
			l1.append(d)
		return l1


class Solution:

	def printSeries(self, N):
		a = [1, 2, 5]
		if N <= 3:
			return a[:N]
		for i in range(3, N):
			a.append(a[i - 1] + a[i - 2] + a[i - 3])
		return a


class Solution:

	def printSeries(self, n):
		if n == 0:
			return []
		if n == 1:
			return [1]
		if n == 2:
			return [1, 2]
		a = 1
		b = 2
		c = 5
		n = n - 3
		l = [a, b, c]
		while n > 0:
			d = a + b + c
			l.append(d)
			a = b
			b = c
			c = d
			n = n - 1
		return l


class Solution:

	def printSeries(self, N):
		l1 = [1, 2, 5]
		if N <= 3:
			return l1[:N]
		else:
			for i in range(3, N):
				c1 = l1[i - 1] + l1[i - 2] + l1[i - 3]
				l1.append(c1)
			return l1


class Solution:

	def printSeries(self, N):
		lis = []
		if N == 0:
			return lis
		if N < 3:
			if N == 1:
				lis.append(1)
				return lis
			if N == 2:
				lis.append(1)
				lis.append(2)
				return lis
			else:
				lis.append(1)
				lis.append(2)
				lis.append(5)
				return lis
		lis.append(1)
		lis.append(2)
		lis.append(5)
		for i in range(3, N):
			lis.append(lis[i - 1] + lis[i - 2] + lis[i - 3])
		return lis