Substring of an vector of strings

how can i solve this question…i find the a bit same one on gfg but i couldn’t understand

@akshat42bajpai, just neet to find the length of longest prefix u can use trie data structure or sort all the string and just find the longest prefix in first and last word that will be the ans or refer