Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use PYTHON only to write the following function . Please remember to foll

ID: 3872257 • Letter: P

Question

Please use PYTHON only to write the following function. Please remember to follow the instructions carefully. Thank you

biggest_subsequence(xs): Given a list of int values, there exists some subsequence whose sum is the biggest. Return the first and last index of this biggest subsequence. Return None when list is empty. Just like the range function, the start index is included, and the stop index is excluded. o Assume: xs is a list of integers. o Restrictions: no extra restrictions. o biggest-subsequence([10,-100, 6, 7, 8,-100]) o biggest_subsequence([1,5, -2, -4,5]) o biggest_subsequence (I-5,-2,-4, -13]) o biggest_subsequence([]) (2,5) (0,2) None

Explanation / Answer

Notice:

First thing you may notice, chegg has knocking down indentation or issues may still be present due to web formatting. Use Ide link (in the comments) in that case. Execute it on your pc and send me comments if anything goes wrong,

**All explanation in comments.**

Check out the online ide code link. Cheers, have a great day mate!

Notice to chegg admins: I have shared IDE link because your chegg editor can't hold python code without errors, so kindly do permit link usage.

Edit 1: Reduced code usage by removing extra pieces of code off.

Code:

import sys

def biggest_subsequence(seq_list):
    """
        Gets start and end indices sequence whose element sum is the highest.
    """

    if len(seq_list) == 0:
        return None

    # Variable to store maximum value, lets init at as low as it can go
    maximum = -1000000000000000000000000000000
    # Start index
    max_start = 0
    # End index
    max_end = 2

    # Generate sequences
    for a in range(len(seq_list)+1):
        for b in range(len(seq_list)+1):
            now_seq = seq_list[a:b]

            # Filter and remove if length < 2 ie remove 1, 0
            if len(now_seq) < 1:
                continue

            # Get sum of sequence
            sequence_sum = sum(now_seq)

            # if sum > previous max
            if sequence_sum > maximum:
                # Update all values
                maximum = sequence_sum
                max_start = a
                max_end = b
    # return the start and end indices
    return (max_start, max_end)


# ######################### TEST SUITE #####################################
def main():
    assert biggest_subsequence([]) == None
    sys.stdout.write(".")
    assert biggest_subsequence([10,-100,6,7,7,-100]) == (2,5)
    sys.stdout.write(".")
    assert biggest_subsequence([1,5,-2,-4,5]) == (0,2)
    sys.stdout.write(".")
    assert biggest_subsequence([-5,-2,-4,-13]) == (1,2)
    sys.stdout.write(".")
    assert biggest_subsequence([-5,-12,-4,-13]) == (2,3)
    sys.stdout.write(".")
    assert biggest_subsequence([4,7,-6,-8,10]) == (0,2)
    sys.stdout.write(".")
    assert biggest_subsequence([10,-100,6,7,8,-100]) == (2,5)
    sys.stdout.write(".")

    xs = [3,6,-7,-8,6,4,-2,-4,6,7,6,3,-3,4,6,5,-3,3,4,5,6,8,-2,8,7,6,5,-3,-4,-5,6]
    orig = xs[:]
    assert biggest_subsequence(xs) == (4,27)
    assert xs == orig
    sys.stdout.write(".")

    print("")

if __name__ == "__main__":
    main()