Question: use python 3 Write a function named longest_sorted_sequence that accepts a list of integers as a parameter and that returns the length of the longest

use python 3

Write a function named longest_sorted_sequence that accepts a list of integers as a parameter and that returns the length of the longest sorted (nondecreasing) sequence of integers in the list. For example, if a variable named list stores the following values:

list = [3, 8, 10, 1, 9, 14, -3, 0, 14, 207, 56, 98, 12] 

then the call of longest_sorted_sequence(list) should return 4 because the longest sorted sequence in the list has four values in it (the sequence -3, 0, 14, 207). Notice that sorted means nondecreasing, which means that the sequence could contain duplicates. For example, if the list stores the following values:

list2 = [17, 42, 3, 5, 5, 5, 8, 2, 4, 6, 1, 19]

Then the function would return 5 for the length of the longest sequence (the sequence 3, 5, 5, 5, 8). Your function should return 0 if passed an empty list. Your function should return 1 if passed a list that is entirely in decreasing order or contains only one element.

Constraints: You may not use any auxiliary data structures (lists, strings, etc.) to solve this problem. Your function should not modify the list that is passed in.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!