File: root - text - article - 2019 - 11 - contiguous-subarray-with-maximum-sum.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 461 Views, 21982 Search Bots | 80 Words
| Browse | Archive
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 461 Views, 21982 Search Bots | 80 Words
| Browse | Archive
Hi, here's your problem today. This problem was recently asked by Twitter:
You are given an array of integers. Find the maximum sum of all possible contiguous subarrays of the array.
Example:
[34, -50, 42, 14, -5, 86]
Given this input array, the output should be 137. The contiguous subarray with the largest sum is [42, 14, -5, 86].
Your solution should run in linear time.
Here's a starting point:
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 461 Views, 21982 Search Bots | 80 Words You are given an array of integers. Find the maximum sum of all possible contiguous subarrays of the array.
Example:
[34, -50, 42, 14, -5, 86]
Given this input array, the output should be 137. The contiguous subarray with the largest sum is [42, 14, -5, 86].
Your solution should run in linear time.
Here's a starting point:
def max_subarray_sum(arr):
# Fill this in.
print max_subarray_sum([34, -50, 42, 14, -5, 86])
# 137
Related Articles
- Daily Interview Problem: Queue Using Two Stacks
- Daily Interview Problem: Find the Number of Islands
- [Daily Problem] Remove Consecutive Nodes that Sum to 0
- Daily Interview Problem: Buddy Strings
- Daily Interview Problem: Reverse Integer
- Daily Interview Problem: Room scheduling
- Daily Interview Problem: Largest BST in a Binary Tree
- Algorithm Interview: Smallest Number that is not a Sum of a Subset of List
- Find Pythagorean Triplets
- Algorithm Interview Question: H-Index
©2006~2024 SteakOverCooked - 0.01229 Seconds(s) - 1611.177 KB/s - 31 Online Memory: 492.52 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
How to Cook a Perfect Steak? | <meta name="robots" content="noindex, follow" />
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - Server PHP Version: 7.4.33
Comments (0)
Read & Write - Normal - Mini - Post - All Comments - Statistics
Be the first one to comment this page !