Myntra Product Catalog Cleanup
Myntra's product catalog system manages millions of product IDs. Periodically, the catalog team performs cleanup operations. Due to various system integrations or manual entry errors, identical product IDs might sometimes appear consecutively in a processing list. These adjacent duplicates need to be efficiently removed to maintain data integrity and optimize downstream processes.
Implement a function cleanCatalog that takes an array of product ID strings. Your task is to process this list and remove all adjacent duplicate product IDs. If removing a pair of duplicates leads to new adjacent duplicates, those should also be removed. This process must continue until no more adjacent duplicates can be found in the list.
productIds - An array of strings, where each string productIds[i] represents a unique product identifier.productIds array is empty, the function should return an empty array."Shirt" is considered different from "shirt".Examples
Example 1
Input:
productIds = ["A", "B", "B", "C", "A"]
Output:
["A", "C", "A"]
Note:
The adjacent 'B's are removed. The list becomes ["A", "C", "A"]. No further adjacent duplicates.
Example 2
Input:
productIds = ["M", "Y", "N", "N", "T", "R", "A", "A", "Y"]
Output:
["M", "Y", "T", "R", "Y"]
Note:
["M", "Y", "N", "N", "T", "R", "A", "A", "Y"] -> Remove 'N','N' -> ["M", "Y", "T", "R", "A", "A", "Y"]["M", "Y", "T", "R", "A", "A", "Y"] -> Remove 'A','A' -> ["M", "Y", "T", "R", "Y"]
No further adjacent duplicates.Example 3
Input:
productIds = ["P", "P", "Q", "Q", "R", "R"]
Output:
[]
Note:
["Q", "Q", "R", "R"]["R", "R"][]Constraints
1 <= productIds.length <= 10^51 <= productIds[i].length <= 10productIds[i] consists of alphanumeric characters (a-z, A-Z, 0-9).Loading editor...