Disney+ Hotstar interview question

DFS algorithm longest common substring from the given string