▁at ▁or ▁after ▁the ▁end ▁of ▁the ▁z - box , ▁we ▁need ▁to ▁do ▁an ▁explicit ▁match ▁to ▁the ▁right ▁of ▁the ▁z - box ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁z [ i ] ▁= ▁a + match _ length ( S , ▁a , ▁r + 1 ) ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁l ▁= ▁i ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁r ▁= ▁i + z [ i ] - 1 ▁▁▁▁▁▁▁▁ ▁else : ▁ ▁# ▁i ▁does ▁not ▁res ide ▁within ▁existing ▁z - box ▁▁▁▁▁▁▁▁▁▁▁▁ ▁z [ i ] ▁= ▁match _ length ( S , ▁ 0 , ▁i ) ▁▁▁▁▁▁▁▁▁▁▁▁ ▁if ▁z [ i ] ▁> ▁ 0 : ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁l ▁= ▁i ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁r ▁= ▁i + z [ i ] - 1 ▁▁▁▁ ▁return ▁z ▁ ▁def ▁bad _ character _ table ( S : ▁str ) ▁-> ▁List [ List [ int ]] : ▁▁▁▁ ▁""" ▁▁▁▁ ▁Gener ates ▁R ▁for ▁S , ▁which ▁is ▁an ▁array ▁indexed ▁by ▁the ▁position ▁of ▁some ▁character ▁c ▁in ▁the ▁▁▁▁ ▁English ▁alphabet . ▁At ▁that ▁index ▁in ▁R ▁is ▁an ▁array ▁of ▁length ▁| S | + 1 , ▁specifying ▁for ▁each ▁▁▁▁ ▁index ▁i ▁in ▁S ▁( plus ▁the ▁index ▁after ▁S ) ▁the ▁next ▁location ▁of ▁character ▁c ▁encountered ▁when ▁▁▁▁ ▁travers ing ▁S ▁from ▁right ▁to ▁left ▁starting ▁at ▁i . ▁This ▁is ▁used ▁for ▁a ▁constant - time ▁lookup ▁▁▁▁ ▁for ▁the ▁bad ▁character ▁rule ▁in ▁the ▁Bo yer - Mo ore ▁string ▁search ▁algorithm , ▁although ▁it ▁has ▁▁▁▁ ▁a ▁much ▁larger ▁size