." "" ▁▁▁▁ ▁best _ sum ▁= ▁ 0 ▁ ▁# ▁or : ▁float (' - inf ') ▁▁▁▁ ▁current _ sum ▁= ▁ 0 ▁▁▁▁ ▁for ▁x ▁in ▁numbers : ▁▁▁▁▁▁▁▁ ▁current _ sum ▁= ▁max ( 0 , ▁current _ sum ▁+ ▁x ) ▁▁▁▁▁▁▁▁ ▁best _ sum ▁= ▁max ( best _ sum , ▁current _ sum ) ▁▁▁▁ ▁return ▁best _ sum ▁ ▁This ▁version ▁of ▁the ▁algorithm ▁will ▁return ▁ 0 ▁if ▁the ▁input ▁contains ▁no ▁positive ▁elements ▁( including ▁when ▁the ▁input ▁is ▁empty ). ▁For ▁the ▁variant ▁of ▁the ▁problem ▁which ▁dis all ows ▁empty ▁sub array s , ▁best _ sum ▁should ▁be ▁initialized ▁to ▁negative ▁infinity ▁instead ▁and ▁also ▁in ▁the ▁for ▁loop ▁current _ sum ▁should ▁be ▁updated ▁as ▁max ( x , ▁current _ sum ▁+ ▁x ). ▁In ▁that ▁case , ▁if ▁the ▁input ▁contains ▁no ▁positive ▁element , ▁the ▁returned ▁value ▁is ▁that ▁of ▁the ▁largest ▁element ▁( i . e ., ▁the ▁least ▁negative ▁value ), ▁or ▁negative ▁infinity ▁if ▁the ▁input ▁was ▁empty . ▁ ▁The ▁algorithm ▁can ▁be ▁modified ▁to ▁keep ▁track ▁of ▁the ▁starting ▁and ▁ending ▁indices ▁of ▁the ▁maximum ▁sub array ▁as ▁well : ▁ ▁def ▁max _ sub array ( numbers ): ▁▁▁▁ ▁""" Find ▁a ▁cont igu ous ▁sub array ▁with ▁the ▁largest ▁sum ." "" ▁▁▁▁ ▁best _ sum ▁= ▁ 0 ▁ ▁# ▁or : ▁float (' - inf ') ▁▁▁▁ ▁best _ start ▁= ▁best _ end ▁= ▁ 0