Available question text
Determine whether an array can be sorted using only swaps between elements whose gcd is >1 — equivalently, check if each number can be moved to its sorted position within connected components formed by edges between numbers that share a prime factor. This reduces to a connectivity/multiset check (e.g., via union-find over prime factors) to see if each component's values can be permuted to match the sorted array.
Related questions
Continue with questions that share topics or the same question type.
- Minimum Pair Removal to Sort Array I
Coding
- Minimum Pair Removal to Sort Array II
Coding
- Minimum Replacements to Sort the Array
Coding · Array · Greedy · Math
- Minimum Right Shifts to Sort the Array
Coding
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 1998. GCD Sort of an Array
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source