There is a factory which produce goods (A, B, C ...). Product A depends on goods-in-process or raw material (E, F, G...). Goods-in-process E depends on other goods-in-process or raw material (H, I, ...). Now the factory discovers that raw material x has quality issues. As a result all goods-in-process or products that are made of raw material x and other goods-in-process or products that are indirectly produced with x must be destroyed. Please design a data structure to describe the relationship between the raw materials, goods-in-process and products. Your algorithm design must satisfy the following two requests efficiently.
- Given a product A, list out all its dependent raw material A - Set.
- Given a raw material x that has quality issues, list out all goods-in-process or product that need to be destroyed.
B then? You said it is product(
produce goods), later you said it is goods-in-process. I am a little confused.
@xidui I guess it's a typo. I have updated the problem description to prevent confusion.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.