values. You may step from position i to position j (i ≠ j) when values[i] and values[j] have a common divisor greater than 1.
Return True if every position can reach every other position in one or more steps, and False otherwise. An array with a single element counts as linked.values=[10, 21, 35] → True
10 and 35 share 5, 21 and 35 share 7. You get from 10 to 21 through 35, so everything is linked.
values=[4, 8, 9, 27] → False
There are two separate groups: {4, 8} sharing 2 and {9, 27} sharing 3.
values=[6, 1] → False
1 shares no divisor above 1 with anything, so it can never be reached.
values=[10, 21, 35]
True
Run checks the first 3 tests in your browser. Submit checks all 132 tests on the server, hidden ones included.