Finding the largest sum of three contiguous number

Complexity

  • Time:
  • Space:

References

Implementations

  • 1
    
    # TODO: Implement in Python
    
  • 1
    2
    3
    4
    5
    6
    7
    8
    
    let sum = D[0] + D[1] + D[2];
    let max = sum;
    
    for (let i = 3; i < D.length; i++) {
      sum += D[i] - D[i - 3];
      if (max < sum) max = sum;
      
    }