Log in from a computer to take this course

You'll need to log in from a computer to start Technical Interview Practice with Python. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store
Learn

Our next problem calculates sums within a list.

Given a list of integers, return the maximum sum possible from a contiguous sub-list. A sub-list is an uninterrupted portion of the list (up to and including the entire list).

nums = [1, -7, 2, 15, -11, 2] maximum_sub_sum(nums) # 17 # The sum of sub-list nums[2:4]

Clarifying Questions:

  • Are there constraints on time or space efficiency?
    • No! Any solution will do.
  • Are all the numbers positive?
    • No! Negative numbers can be in the input.
  • How big or small can the sub-list be?
    • From a single element to the entire list.

Instructions

1.

Write a function maximum_sub_sum() which has a single parameter: my_list.

maximum_sub_sum() should return the maximum sum of contiguous values in my_list.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?