Hello everyone I am Santiago
I am doing a homework with python, I let the homework:
LONGEST INCREASING SUB-SEQUENCE
Write a program, which reads a sequence of integers (in one string, the numbers are separated by
spaces). The program then prints its longest increasing sub-sequence. If there are several increasing
sub-sequences of the same length, the program prints the first one. A sequence is increasing when
𝑎𝑎𝑖𝑖 < 𝑎𝑎𝑖𝑖+1 for each 𝑖𝑖.
Examples:
Input: 1 7 8 3 4 6 8 9 0 5 1 2 3
Output: 3 4 6 8 9
Input: 5 4 2 3 4 9 9 9 -8 -5 -3 -2 -1
Output: -8 -5 -3 -2 -1
Input: -3 -2 8
Output: -3 -2 8
Input: 5 4 3 2 1 0
Output: 5
I wrote some code and it is working pretty good (all the examples are working except the 1st one
). I let my code:
My problem is that I need to put my input as one string, seprate by spaces, but I don't know how to do that
. Also I wanted to do my array in a user give (Ex.: in(input("Write the numbers to find the longer sub-sequence")) but I tried but didn't work and I dont know why
.
P.S.: I don't know if is the best way to do this homework but I don't have experience in python, is just my 1st year of programming.
Thank you everyone for help me :D

I am doing a homework with python, I let the homework:
LONGEST INCREASING SUB-SEQUENCE
Write a program, which reads a sequence of integers (in one string, the numbers are separated by
spaces). The program then prints its longest increasing sub-sequence. If there are several increasing
sub-sequences of the same length, the program prints the first one. A sequence is increasing when
𝑎𝑎𝑖𝑖 < 𝑎𝑎𝑖𝑖+1 for each 𝑖𝑖.
Examples:
Input: 1 7 8 3 4 6 8 9 0 5 1 2 3
Output: 3 4 6 8 9
Input: 5 4 2 3 4 9 9 9 -8 -5 -3 -2 -1
Output: -8 -5 -3 -2 -1
Input: -3 -2 8
Output: -3 -2 8
Input: 5 4 3 2 1 0
Output: 5
I wrote some code and it is working pretty good (all the examples are working except the 1st one

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
def printLIS(arr: list ): for x in arr: print (x, end = " " ) print () def constructPrintLIS(arr: list , n: int ): l = [[] for i in range (n)] l[ 0 ].append(arr[ 0 ]) for i in range ( 1 , n): for j in range (i): if arr[i] > arr[j] and ( len (l[i]) < len (l[j]) + 1 ): l[i] = l[j].copy() l[i].append(arr[i]) maxx = l[ 0 ] for x in l: if len (x) > len (maxx): maxx = x printLIS(maxx) if __name__ = = "__main__" : arr = [ 1 , 7 , 8 , 3 , 4 , 6 , 8 , 9 , 0 , 5 , 1 , 2 , 3 ] n = len (arr) constructPrintLIS(arr, n) |


P.S.: I don't know if is the best way to do this homework but I don't have experience in python, is just my 1st year of programming.
Thank you everyone for help me :D