Design an autocomplete function for IDE. Given the String[] below, some capital letters and small letters are included in the input. We are asked to implement the autocomplete, and all capital letters must be matched. ex:
String[] className {
"GraphView",
"DataGraphView",
"DataController",
"GraphViewController",
"DataScienceView"
}
autocomplete(String[] className, "Data"); --> {"DataGraphView", "DataController", "DataScienceView"};
autocomplete(String[] className, "GVi"); --> {"GraphView", "GraphViewController"};
autocomplete(String[] className, "GraphController"); --> {""};
I think maybe I could use trie, but I don't know how to handle the case2, which is "GVi". Does anyone who could help me on this? Any idea or codes are appreciated! Thanks a lot!