Please improve my code for the following output. I want a better time complexity and space complexity. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Please improve my code for the following output. I want a better time complexity and space complexity.

Q. Write a program which gives the given output (7 rows) pattern for the corresponding integer input. input = 4 output:- 4 8 9 12 14 16 16 17 18 19 36 38 40 42 44 46 32 33 34 35 36 37 38 39 108 110 112 114 116 118 120 122 124 My code:(Python) a=int(input("enter: ")) d=a rows=7 k=0 l=1 print(a) for i in range(rows-1): if (i%2!=0): a=a*3 k+=3 for j in range(k): print(a+(2*j), end=" ") print() else: d*=2 l*=2 for j in range(l): print(d+j, end=" ") print()

24th Sep 2021, 8:35 PM
Prasenjit Kumar
Prasenjit Kumar - avatar
3 Answers
+ 3
U forgot to say what yrs program should to do
24th Sep 2021, 11:09 PM
TriXioN
TriXioN - avatar
0
The program is supposed to give that pattern of numbers as output in 7 rows for a given integer input. This question was asked in a test and my answer was this python code. As one can see I have used 7 variables. I just want to know an alternate code which gives the same output with better logic and improved time complexity.
25th Sep 2021, 5:58 PM
Prasenjit Kumar
Prasenjit Kumar - avatar
0
Prasenjit Kumar Sry, but i have no idea whats it, and it seems to me that yr code is pretty fast and simple
26th Sep 2021, 5:29 PM
TriXioN
TriXioN - avatar