The Output Peak
A hard Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- hard
- Seniority
- L5
Problem
Given a list of integers (possibly negative), find the contiguous subarray with the largest sum. Return a 2-element list [sum, subarray], where sum is an int and subarray is a list of ints. If multiple subarrays tie for max sum, return the earliest (smallest start index). The input always has at least one element, and the subarray must contain at least one element even when every value is negative.
Summary
One stretch outpaced all the others.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.