Given an array of Strings, group them such that all the strings in that group are either substring or super strinngs of rest of them.
Ex: ["string", "ring", "ing", "ringo"]
Ans: Two groups - {"string", "ring", "ing"}, {"ring", "ing", "ringo"}
Ex: ["dragon", "dra", "gon"]
Ans: 2 -{"dragon", "dra"}, {"dragon", "gon"}
Ex: ["string", "str", "s"]
Ans: 2 - {"string", "str", "s"}
Interviewer gave the hint that, I should be sorting them by length desc, and then iterate the array and start making the groups.
Following this lead, I gave some List of lists based solution, but it did not work for all cases. Is it some graph problem related to figuring out connected components somehow? Is this question already present on leetcode?