FastPrepVariadic Function Library Matches

Variadic Function Library Matches

IBM logoIBM● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

A function library registers functions in order. Function i has name names[i], declared parameter types parameterTypes[i], and flag isVariadic[i].

A non-variadic function matches a query only when its declared types equal the query exactly. A variadic declaration must be non-empty: every declared type before the last is a fixed prefix, and the final declared type accepts zero or more query arguments. Type tokens compare by exact case-sensitive equality.

Return the names of every matching function in registration order.

Function

findFunctionMatches(names: String[], parameterTypes: String[][], isVariadic: boolean[], queryTypes: String[]) → String[]

Examples

Example 1

names = ["foo","bar","baz"]parameterTypes = [["String"],["String","Integer"],["String","Integer"]]isVariadic = [false,true,false]queryTypes = ["String"]return = ["foo","bar"]

The variadic final Integer consumes zero arguments, while the fixed two-parameter function does not match.

Example 2

names = ["join","pair"]parameterTypes = [["String","String"],["String","String"]]isVariadic = [true,false]queryTypes = ["String","String","String"]return = ["join"]

The final type of join repeats to consume both trailing arguments.

Example 3

names = ["sum"]parameterTypes = [["Integer"]]isVariadic = [true]queryTypes = []return = ["sum"]

A declaration consisting only of its variadic type accepts an empty query.

Constraints

  • names.length == parameterTypes.length == isVariadic.length.
  • 0 <= names.length <= 100000.
  • The total number of declared and query type tokens is at most 300000.
  • Names and type tokens are non-empty ASCII strings of length at most 100.
  • Every variadic declaration contains at least one type.

More IBM problems

See IBM hiring insights
public String[] findFunctionMatches(String[] names, String[][] parameterTypes, boolean[] isVariadic, String[] queryTypes) {
    // Write your solution here.
}
names["foo","bar","baz"]
parameterTypes[["String"],["String","Integer"],["String","Integer"]]
isVariadic[false,true,false]
queryTypes["String"]
expected["foo", "bar"]
Checking account…