But I wrotethisjustforclarityonwhatwe'regonnadoHereistakeElsie S O.
P.
Q andminusoneemonElsie's ofPeak, youand M minusone, andwe'lltakethemaximumoneofthoseonreturnthathere's a quickanalysisover a recursivesolution.
Well, lookatoneoftheworstcasenowIris, when P and Q don't haveanycharactersincommonWell, lookatthisparticularexample.
When P goes a a andCurieCoastBBBfirst, we'llcall L C s A p cutetothreebecausewehavetwocharactersonthreecharacters.
Andtofindthatweneedtocall L.
C s offPeakyou 13 I just I beratedas l 13 We'llalsoneedtocall l 22 ontoFinal 13 Weneedtocall l 03 whichisabasecaseand I wantto.
Andsothat's whatthisdiagramshowson.
Asyoucansee, theproblemwiththisapproachisthatthereare a lotofduplicatesinourcompetition.
Sowe'recomputing l onetoo, twicetheexactsamecondition.
We'recomputing l 113 times, andthat's whythisis a verywastefulandit's veryslow.
Infact, thetimeittakestofindtheorginalLCSis a bottleinordertotodepartofandplus M intheworstcasescenarioanddynamicprogramsayswhynotjuststoreallthoseintermediateresultssowecanmakethisfunctionrunfaster?