FastPrepGenerate Parameter Combinations

Generate Parameter Combinations

Gecko Robotics logoGecko Robotics● MediumNEW GRADOAPHONE SCREEN
Learn

Problem statement

Given an ordered list of parameter value lists, return every combination that chooses exactly one value from each list.

Preserve parameter order within each combination. Enumerate combinations lexicographically according to the given order of values in each parameter list. If there are no parameters, return one empty combination. If any parameter has no values, return no combinations.

Function

generateParameterCombinations(parameters: String[][]) → String[][]

Examples

Example 1

parameters = [["red","blue"],["S","M"]]return = [["red","S"],["red","M"],["blue","S"],["blue","M"]]

Each color is paired with each size. The first attribute changes more slowly because combinations are enumerated from left to right.

Example 2

parameters = [["us"],["free","pro"],["light","dark"]]return = [["us","free","light"],["us","free","dark"],["us","pro","light"],["us","pro","dark"]]

The single region appears in every row, while the two later attributes generate four combinations.

Example 3

parameters = []return = [[]]

The Cartesian product of zero attribute sets contains one empty assignment.

Constraints

  • 0 <= parameters.length <= 12.
  • Each value is a non-empty alphanumeric string that may also contain underscore, hyphen, or period.
  • Values within one list are distinct and already sorted.
  • The total number of returned combinations is at most 100000.
  • Do not use a library Cartesian-product helper.

More Gecko Robotics problems

See Gecko Robotics hiring insights
public String[][] generateParameterCombinations(String[][] parameters) {
    // write your code here
}
parameters[["red","blue"],["S","M"]]
expected[["red", "S"], ["red", "M"], ["blue", "S"], ["blue", "M"]]
Checking account…