Algorithm for SIMNUM

Can someone provide an editorial for the problem asked in this contest .
Problem link:-Similiarity number
I think the problem will be solved using LCP array but not getting any directions. Please someone help.