The COVID-19 pandemic situation has challenged the medical equipment supply chain leading to an uneven distribution of personal protective equipment (PPEs) at local hospitals. Assuming the following:
- These hospitals are represented as nodes (of type BSTNode) in a binary tree.
- There are N numbers of hospitals.
- There are N numbers of PPEs.
- Even distribution means each hospital receives 1 PPE (in a real situation, this 1 PPE can be 1 truckload of PPEs but we are using 1 PPE to simplify this problem).
3 1
/ —–> /
0 0 1 1
For brevity, the above tree can be flattened level-order-wide in an array as [3,0,0]. The resulting tree is [1,1,1]. The above initial distribution requires TWO (2) moves to arrive at an even distribution with each node receiving 1 PPE, namely, 1 PPE going from root -> root. left, and another PPE from root -> root. right. You will start with the following code template.


0 comments