CamelCase Class Name Autocomplete
Problem statement
You are given a list of class names written in CamelCase, classNames, and a search string query, also in CamelCase.
Split every string into words: a new word starts at each uppercase letter. For example, GraphViewController has the words Graph, View and Controller, and XMLParser has X, M, L and Parser.
A class name matches the query when the query has k words, the name has at least k words, and for every i from 1 to k, the i-th query word is a prefix of the i-th word of the name. Letters are compared exactly, so case matters.
Return all matching class names in the order they appear in classNames. Return an empty list if none match.
Function
autocomplete(classNames: String[], query: String) → List<String>Examples
Example 1
classNames = ["GraphView","DetailedDataView","DataGraphView","DataController","GraphViewController","MouseClickHandler","MathCalculationHandler","DataScienceView"]query = "GraVi"return = ["GraphView","GraphViewController"]The query splits into Gra and Vi. GraphView starts with the words Graph and View, and GraphViewController starts with the same two words, so both match. DataGraphView also contains Graph and View, but its first word is Data, so it does not match.
Example 2
classNames = ["UserProfileCard","UserPanel","UploadProgressCard","ProfileCard"]query = "UPC"return = ["UserProfileCard","UploadProgressCard"]The query words are U, P and C. UserProfileCard and UploadProgressCard have three words starting with those letters. UserPanel has only two words, and ProfileCard starts with P, so neither matches.
Example 3
classNames = ["UserPanel","PanelView","PageCard"]query = "Pa"return = ["PanelView","PageCard"]The single query word Pa must start the first word of a name. It starts Panel and Page, but the first word of UserPanel is User. The matches stay in their input order.
Constraints
1 <= classNames.length <= 10001 <= classNames[i].length, query.length <= 40- Every class name and the query contain only English letters and start with an uppercase letter.
- All class names are different.