Aug-27-2021, 04:53 PM
(Feb-27-2021, 08:19 PM)SantiagoPB Wrote:def longestIncreasing(arr): res = [] temp = [arr[0]] for i in range(1, len(arr)): if arr[i] > arr[i-1]: temp.append(arr[i]) if i == len(arr)-1 and len(temp) > len(res): res = temp else: if len(temp) > len(res): res = temp temp = [arr[i]] return res def output(arr): for n, i in enumerate(arr): if n == len(arr)-1: print(i) else: print(i, end = ' ') if __name__ == "__main__": arr = [1, 7, 8, 3, 4, 6, 8, 9, 0, 5, 1, 2, 3] output(longestIncreasing(arr))
Output:3 4 6 8 9