Algorithm · Amazon · Hard
Below are Python 3 solutions. 1. Merge Product Categories Use a Disjoint Set Union structure to merge products that appear in the same pair. After processing all pairs, count the size of each connected component and return the component count followed by sorted component sizes. Time: $$O(p \alpha(u) + u \log u)$$, where $$p$$ is the number of pairs and $$u$$ is the number of unique products. Space: $$O(u)$$. 2. Validate and Produce a Course Schedule Use Kahn's algorithm for…
Checking your access…