EXPEDIA Coding Question β Solved
Given two servers and the time taken to upgrade each server in seconds, denoted by t1 and t2 respectively, in one second, one server undergoes the upgrade process. The servers receive requests at certain time intervals and pause upgrades during those seconds. The servers receive requests at multiples of req1 and req2 respectively. Determine the minimum total time (in seconds) required to upgrade both servers.
Notes:
. Only one server undergoes the upgrade process at any given second.
. There may be seconds during which no server is undergoing an upgrade.
Example:
req1 = 2
t1 = 3
req2 = 3
t2 = 1
The 1st server takes 3 seconds to upgrade, and it receives requests on seconds that are multiples of 2. Similarly, the 2nd server upgrades in 1 second and receives requests on seconds that are multiples of 3.
The 1st server upgrades in the 1st, 3rd, and 5th seconds, while the 2nd server upgrades in the 2nd second. Note that none of the numbers from [1, 3, 5] is divisible by req1 = 2. Similarly, [2] is not divisible by req2 = 3. Thus, the minimum time required is 5 seconds.
Function Description:
Complete the function getMinUpgradationTime in the editor below.
getMinUpgradationTime takes the following parameter(s):
int req1: indicates that the first server receives requests at multiples of req1
int t1: the total time in seconds to upgrade the first server
int req2: indicates that the second server receives requests at multiples of req2
int t2: the total time in seconds to upgrade the second server
Returns:
long: the minimum total time (in seconds) required to upgrade both servers
Constraints:
Β· 2 β€ req1, req2 β€ 3 * 10^4
Β· 1 β€ t1, t2 β€ 10^9
Sample Input:
2
1
FUNCTION
req1 = 2
t1 = 1
Input Format For Custom Testing:
Sample Case 0
Sample Input For Custom Testing:
STDIN