Find the maximum interval sum in a list of real numbers

后端 未结 9 1313
长情又很酷
长情又很酷 2020-12-10 17:20

Here\'s an interview questions that a colleague asked for a programming position. I thought this was great for watching the interviewee think it through. I\'d love to get re

9条回答
  •  时光说笑
    2020-12-10 18:11

    The complexity is just O(n) for Kadane's algorithm:

    The algorithm keeps track of the tentative maximum subsequence in (maxSum, maxStartIndex, maxEndIndex). It accumulates a partial sum in currentMaxSum and updates the optimal range when this partial sum becomes larger than maxSum.

提交回复
热议问题