Skip to content

Practice Rearrange Products Table

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#1795
LeetCode Problem

Rearrange Products Table

Problem Statement

Tables: Products(product_id INT, store1 INT, store2 INT, store3 INT). Products.product_id is unique. store1, store2 and store3 hold prices; null means the product is unavailable at that store. Return one row per available product-store pair with product_id, store and price. The store label is store1, store2 or store3. Exclude null prices while keeping zero prices. Output order is unrestricted.

Source: Rearrange Products Table on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
Products table: +------------+--------+--------+--------+ | product_id | store1 | store2 | store3 | +------------+--------+--------+--------+ | 0          | 95     | 100    | 105    | | 1          | 70     | null   | 80     | +------------+--------+--------+--------+
Output
+------------+--------+-------+ | product_id | store  | price | +------------+--------+-------+ | 0          | store1 | 95    | | 0          | store2 | 100   | | 0          | store3 | 105   | | 1          | store1 | 70    | | 1          | store3 | 80    | +------------+--------+-------+

Related LeetCode Problems

Practice more problems similar to Rearrange Products Table.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.