An AWS client has brought servers and databases from data centers
in different parts of the world for their application. For simplicity, let's assume all the servers and data centers are located on a 1- dimensional line.
You have been given the task of optimizing the network connection. Each data center must be connected to a server. The positions of n data centers and n servers are given in the form of arrays. Any particular data center, center[1], can deliver to any particular server destination, destination[J]. The lag is defined distance between a data center at location x and a lerver destination at location yis | x- yl, i.e., the absolute difference between x and y. Determine the minimum lag to establish the entire network.
Example
There are n = 3 connections, the positions of data centers, center = [1, 2, 2], and the positions of the server destinations, destination = [5, 2, 4].
יש לך מערך עם כדורים אדומים, צהובים וירוקים.
אתה צריך לסדר אותו כך שכל הכדורים האדומים יהיו בהתחלה וכל הכדורים הירוקים יהיו בסוף.
פולאו‑אפ: עשה זאת מבלי לצרוך זכרון נוסף.