Generate Parameter Combinations
Updated
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 Online Assessment questions
Similar questions at other companies
- Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions
- SubsetsTemu · PHONE SCREENTemu interview questions
- PermutationsEPAM · PHONE SCREENEPAM interview questions
- Expand Attribute CombinationsPinterest · PHONE SCREENPinterest interview questions
- Alternating Parity PermutationsGoldman Sachs · OAGoldman Sachs interview questions
- All Subsets with a Given SumApple · PHONE SCREENApple interview questions
- Combination Sum with Unlimited ReuseIMC Trading · PHONE SCREENIMC Trading interview questions
- SubsetsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Validate a Mahjong Hand PartitionDuolingo · PHONE SCREENDuolingo interview questions
- Winning Draws for a Mahjong HandZip · PHONE SCREENZip interview questions