Get Minimum Time
Learn this problemProblem statement
Developers at Amazon have deployed an application with a distributed database. It is stored on total_servers different servers numbered from 1 to total_servers that are connected in a circular fashion, i.e. 1 is connected to 2, 2 is connected to 3, and so on until total_servers connects back to 1.
There is a subset of servers represented by an array servers of integers. They need to transfer the data to each other to be synchronized. Data transfer from one server to one it is directly connected to takes 1 unit of time. Starting from any server, find the minimum amount of time to transfer the data to all the other servers.
Function
getMinTime(total_servers: int, servers: int[]) → int
Complete the function getMinTime in the editor.
getMinTime takes the following arguments:
int total_servers: The number of servers in the systemint servers[n]: The servers to share the data with
Returns
int: The minimum time required to transfer the data on all the servers
🍊 A million thanks, spike 👍
Examples
Example 1
total_servers = 8servers = [2, 6, 8]return = 4
Example 2
total_servers = 5servers = [1, 5]return = 1Example 3
total_servers = 10servers = [4, 6, 2, 9]return = 7Constraints
1 ≤ total_servers ≤ 1091 ≤ n ≤ 1051 ≤ servers[i] ≤ n
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026