Practice Greatest Common Divisor Traversal
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given a 0-indexed integer array nums, and you are allowed to traverse between its indices. You can traverse between index i and index j, i != j, if and only if gcd(nums[i], nums[j]) > 1, where gcd is the greatest common divisor. Your task is to determine if for every pair of indices i and j in nums, where i < j, there exists a sequence of traversals that can take us from i to j. Return true if it is possible to traverse between all such pairs of indices, or false otherwise.
Source: Greatest Common Divisor Traversal on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [2,3,6]
true
# Example 2
nums = [3,9,5]
false
# Example 3
nums = [4,3,12,8]
true
Constraints
Related LeetCode Problems
Practice more problems similar to Greatest Common Divisor Traversal.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.