Problem · Array
Sort Products by Aisle With Frozen Items Last
Learn this problemProblem statement
Each product record has the form sku|name|quantity|priceCents|aisle|isFrozen. Return the product SKUs in this deterministic order:
- All non-frozen products before all frozen products.
- Within each group, aisle number descending.
- Within the same group and aisle, SKU lexicographically ascending.
The other product fields do not affect ordering.
Function
sortProductSkus(products: String[]) → String[]Examples
Example 1
products = ["A7|Apple|1|100|7|false","A2|Bread|1|200|2|false","F100|Ice|1|300|100|true","F3|Peas|1|400|3|true"]return = ["A7","A2","F100","F3"]Both non-frozen records come first with aisle 7 before aisle 2. Frozen aisle 100 still follows every non-frozen item.
Example 2
products = ["B|B|1|1|5|false","A|A|1|1|5|false","D|D|1|1|8|true","C|C|1|1|8|true"]return = ["A","B","C","D"]Each pair shares its group and aisle, so SKU order breaks both ties.
Example 3
products = ["Z|Z|1|1|-2|true","X|X|1|1|0|false","Y|Y|1|1|-5|false"]return = ["X","Y","Z"]Descending aisle order places non-frozen aisle 0 before -5; the frozen record remains last.
Constraints
1 <= products.length <= 10^5.- Every record is syntactically valid and contains a unique non-empty SKU.
- String fields do not contain
|. aisleis a signed 32-bit integer, andisFrozenistrueorfalse.