FastPrepCamelCase Class Name Autocomplete
Problems/CamelCase Class Name Autocomplete

CamelCase Class Name Autocomplete

Indeed logoIndeed● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The task is autocomplete over CamelCase class names. In the report's one example, the query GraVi picks GraphView and GraphViewController out of eight names such as DataGraphView.

The report gives only this example. Here, a new word starts at every capital letter, and the query's words must start the first words of a class name in the same order, with no words skipped. Letters are case-sensitive, matches come back in input order, and there is one query. There are at most 1000 different class names, and every string has 1 to 40 letters.

The judged task matches the report at about 80%.

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 <= 1000
  • 1 <= 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.

More Indeed problems

  • Insert into an Unrolled Linked ListPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Course Completion OrderPHONE SCREEN · Seen May 2025
  • Recipes You Can PreparePHONE SCREEN · Seen May 2025
All Indeed interview questionsSee Indeed hiring insights
Saved
class Solution {
    public List<String> autocomplete(String[] classNames, String query) {
        // Write your code here.
    }
}
Checking account…