Education + Jobs Hiring Website - 2025
0 like 0 dislike
26 views
Q1)

There are n hospitals represented by 1,2,3,…,n

Few of them are connected by roads. The list of all connected hospitals is given as a

m*2 array where m are the number of roads. Ex: [[1,2], [2,3], [2,4]]

Each hospital can contain either required or surplus or deficient amount of vaccines. A

list representing the vaccine status of each hospital is given.

A hospital with surplus vaccines can ship out any number of vaccines to hospitals.

Travelling between any two directly connected hospitals takes 1 unit of time.

What is the minimum time required to make all hospitals have required number of

vaccines?

Ex:

5 hospitals. roads - [[1,2], [2,3], [2,4], [4, 5]]

i.e, 1 --- 2 --- 3

 |

 4 --- 5

surplus status - [1, 0, -1, -1, 1] where 1 represents surplus, 0 represents self-sufficient

and -1 represents deficient.

Output: 2

Explanation: hospitals 3 & 4 are deficient, 3 is closest to 1(surplus) which is 2 units of

time and 4 is closest to 5 which is 1 unit of time.

1 --- 2 --- 3 – 6 –7 — 8 – 9 – 10

 |

 4 --- 5

[2, 0 , -5, -1,1,0 , 0,4,0,1 ]
ago in Online Assessments by Expert (138,260 points) | 26 views

Please log in or register to answer this question.