▁ ▁# ▁or : ▁None ▁▁▁▁ ▁current _ sum ▁= ▁ 0 ▁▁▁▁ ▁for ▁current _ end , ▁x ▁in ▁enumerate ( numbers ): ▁▁▁▁▁▁▁▁ ▁if ▁current _ sum ▁<= ▁ 0 : ▁▁▁▁▁▁▁▁▁▁▁▁ ▁# ▁Start ▁a ▁new ▁sequence ▁at ▁the ▁current ▁element ▁▁▁▁▁▁▁▁▁▁▁▁ ▁current _ start ▁= ▁current _ end ▁▁▁▁▁▁▁▁▁▁▁▁ ▁current _ sum ▁= ▁x ▁▁▁▁▁▁▁▁ ▁else : ▁▁▁▁▁▁▁▁▁▁▁▁ ▁# ▁Ext end ▁the ▁existing ▁sequence ▁with ▁the ▁current ▁element ▁▁▁▁▁▁▁▁▁▁▁▁ ▁current _ sum ▁+= ▁x ▁▁▁▁▁▁▁▁▁ ▁if ▁current _ sum ▁> ▁best _ sum : ▁▁▁▁▁▁▁▁▁▁▁▁ ▁best _ sum ▁= ▁current _ sum ▁▁▁▁▁▁▁▁▁▁▁▁ ▁best _ start ▁= ▁current _ start ▁▁▁▁▁▁▁▁▁▁▁▁ ▁best _ end ▁= ▁current _ end ▁+ ▁ 1 ▁ ▁# ▁the ▁+ 1 ▁is ▁to ▁make ▁' best _ end ' ▁exclusive ▁▁▁▁▁ ▁return ▁best _ sum , ▁best _ start , ▁best _ end ▁ ▁In ▁Python , ▁arrays ▁are ▁indexed ▁starting ▁from ▁ 0 , ▁and ▁the ▁end ▁index ▁is ▁typically ▁ex cluded , ▁so ▁that ▁the ▁sub array ▁[ 2 2 , ▁ 3 3 ] ▁in ▁the ▁array ▁[- 1 1 , ▁ 2 2 , ▁ 3 3 , ▁- 4 4 ] ▁would ▁start ▁at ▁index ▁ 1 ▁and ▁end ▁at ▁index ▁ 3 . ▁ ▁Because ▁of ▁the ▁way ▁this ▁algorithm ▁uses ▁optimal ▁sub struct ures ▁( the ▁maximum ▁sub array ▁ending ▁at ▁each ▁position ▁is ▁calculated ▁in ▁a ▁simple ▁way ▁from ▁a ▁related ▁but ▁smaller ▁and ▁over la pping ▁sub problem : ▁the ▁maximum ▁sub array ▁ending ▁at ▁the