
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Can we build a graph with all the prime numbers and the original array?
We can use union-find to determine which indices are connected (i.e., which indices can be swapped).