Question: Plz finish the code in Python Question 5 ( 2 0 marks ) A sequence of numbers, denoted as { a 1 , a 2
Plz finish the code in Python
Question marks
A sequence of numbers, denoted as dots, is called monotonic if it either consis
tently increases or consistently decreases as you move along the sequence. There are two
types of monotonic sequences:
Monotonic increasing sequence: for all eg
Monotonic decreasing sequence: for all eg
Write a function longestmonotonicsubseqsizenums: listint int that takes
a nonempty list of integers nums and returns the length of the longest monotonic subsequence
found from the consecutive elements of the list.
Notes:
Instead of writing two redundant loops, one for finding the longest monotonic increasing
subsequence and another for the longest monotonic decreasing subsequence, that differ
only by the comparison operator, think of how to avoid redundant code. For example,
the eval function allows evaluating an expression, ega b of a string formed
from your desired operator and operands.
This question aims at finding subsequences from consecutive elements. Subsequences
formed from hopping elements do not count. For example, for the
expected result is subsequence instead of subsequence
Sample Runs:
longestmonotonicsubseqsize
# Two monotonic subsequences found:
# monotonic increasing the longest
# monotonic decreasing
# The function should return in this example.
longestmonotonicsubseqsize
# Two monotonic subsequences found:
# monotonic decreasing the longest
# monotonic increasing
# The function should return in this example.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
