FastPrepInventory Outfit Combinations

Inventory Outfit Combinations

Roblox logoRoblox● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

A user’s inventory is described by parallel arrays categories and itemIds. Each position identifies one item and its clothing category.

For this exercise, assume an outfit contains exactly one item from every category present in the inventory. Every combination of those choices is compatible, and no additional optional category or compatibility rule applies. Different item IDs are different choices.

Return all outfits. Within each outfit, list item IDs in increasing category order. Sort the outfit rows lexicographically by their item IDs: compare the first differing position numerically. The input arrays may be unsorted. An empty inventory returns an empty array of outfits.

Function

combineOutfits(categories: int[], itemIds: int[]) → int[][]

Examples

Example 1

categories = [1,0,1,0]itemIds = [20,3,10,1]return = [[1,10],[1,20],[3,10],[3,20]]

Category 0 offers 1 or 3, and category 1 offers 10 or 20. List all four ordered combinations.

Example 2

categories = [3,3]itemIds = [9,2]return = [[2],[9]]

Only category 3 is present, so each of its items forms one outfit.

Example 3

categories = []itemIds = []return = []

An empty inventory produces no outfit.

Constraints

  • 0 <= itemIds.length <= 16 and categories.length = itemIds.length.
  • 0 <= categories[i] <= 3, and each category contains at most 4 items.
  • Item IDs are distinct integers in 0..10^9.
  • At most 256 outfits can be returned.

More Roblox problems

See Roblox hiring insights
public int[][] combineOutfits(int[] categories, int[] itemIds) {
    // write your code here
}
categories[1,0,1,0]
itemIds[20,3,10,1]
expected[[1,10],[1,20],[3,10],[3,20]]
Checking account…