File tree Expand file tree Collapse file tree 1 file changed +11
-16
lines changed
Expand file tree Collapse file tree 1 file changed +11
-16
lines changed Original file line number Diff line number Diff line change 44Domain : Python
55Author : Ahmedur Rahman Shovon
66Created : 15 July 2016
7+ Updated : 08 February 2023
78Problem : https://www.hackerrank.com/challenges/map-and-lambda-expression/problem
89"""
9- # Enter your code here. Read input from STDIN. Print output to STDOUT
10- def sqr (a ):
11- return a * a * a
10+ cube = lambda x : x * x * x
1211
13-
14- n = int (input ())
15- if n == 0 :
16- print ("[]" )
17- elif n == 1 :
18- print ("[0]" )
19- else :
20- ar = [0 ] * n
21- ar [0 ] = 0
22- ar [1 ] = 1
12+ def fibonacci (n ):
13+ ar = [0 , 1 ]
14+ if n < 2 :
15+ return ar [:n ]
2316 for i in range (2 , n ):
24- ar [i ] = ar [i - 1 ] + ar [i - 2 ]
17+ ar .append (ar [i - 1 ] + ar [i - 2 ])
18+ return ar
2519
26- ar = map (sqr , ar )
27- print (list (ar ))
20+ if __name__ == '__main__' :
21+ n = int (input ())
22+ print (list (map (cube , fibonacci (n ))))
You can’t perform that action at this time.
0 commit comments