Reported September 2023
Gecko Roboticsbacktracking

Generate Parameter Combinations

Reported by candidates from Gecko Robotics's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Gecko Robotics OA. Under 2s to a working solution.
Founder's read

Gecko Robotics reportedly asked this one in September 2023, and it's a Cartesian product in disguise. Pick one value from each list, keep the order, return every row. No trick graph, no clever math. It's backtracking, and the edge cases are where people lose points. If you've got an OA invite for this, the real job is handling empty inputs cleanly and not reaching for a library helper, since the problem bans it. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but this one is easy to own once you see the shape.

The problem

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The problem reduces to depth-first recursion over the parameter index. At depth i, loop through parameters[i] in the given order, push the value onto a current path, recurse to i+1, then pop. When the index equals parameters.length, copy the path into the results. Because you iterate in the given order, the output is lexicographic for free, and the leftmost list changes slowest. The pitfalls are all edge cases. Zero parameters must return [[]], one empty combination. Any empty list must return [], and the recursion handles that naturally since the loop never runs. The other classic bug is pushing the path itself instead of a copy, so every row ends up identical. An iterative version with an index odometer works too. If you freeze on the live OA, StealthCoder is the hedge that gets the skeleton on screen fast.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Generate Parameter Combinations cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Gecko Robotics's OA.

Gecko Robotics reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Generate Parameter Combinations FAQ

What's the trick in Generate Parameter Combinations?+

It's a Cartesian product, so use backtracking by parameter index. At each level loop over that list's values, append one, recurse, then remove it. At the last level, copy the current path into the results. Iterating in the given order gives lexicographic output automatically.

How should I handle empty inputs?+

Zero parameters returns [[]], one empty combination, which falls out of the base case when index 0 equals the length. If any inner list is empty, return [] because the loop at that level never executes. Test both before submitting, since the examples only show the first.

Can I use itertools.product or a similar helper?+

No. The constraints say not to use a library Cartesian-product helper. Write the recursion or an iterative odometer yourself. It's about ten lines, so you're not losing anything, and it avoids a disqualifying shortcut.

What's the time complexity, and will it fit?+

The output is capped at 100000 combinations, and each has up to 12 values. So work is roughly the number of combinations times the parameter count, around a million operations. Recursion depth is at most 12, so there's no stack concern. Output size dominates, not the algorithm.

How do I prepare for this in 48 hours?+

Write the backtracking version from memory twice, once recursive and once iterative. Then run the three edge cases: empty parameters, an empty inner list, and a single-value list. Also practice copying the path correctly. That covers the whole problem and similar subset or combination questions.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Gecko Robotics.

OA at Gecko Robotics?
Invisible during screen share
Get it