A network is made out of n machines that are numbered from 1 to n. This network has a set of connections, which can be used to send information to both directions between two machines. Create the following functions:
void addConnection(int a, int b)
- adds connection between machines a and b.
boolean checkConnection(int x, int y)
- returns true if there is a connection between machines x and y, otherwise it returns false.
1 <= n <= 5000 where for every n the runtime should be < 1000ms.
Example inputs and outputs:
Communications c = new Communications(6);
c.checkConnection(1,4); // true
c.checkConnection(2,5); // false
c.checkConnection(5,6); // true
Otherwise, I’ll get depressed and have to cancel the show 😭