-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Open
Description
Bug Report for https://neetcode.io/problems/greatest-common-divisor-traversal
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
The problem has accepted the below solution but it fails for the input : nums=[4,9,6,7,49] , I think this test case must be added.
class Solution {
public int gcd(int a, int b){
if(b>a) return gcd(b,a);
if(b==0) return a;
return gcd(b, a%b);
}
public boolean canTraverseAllPairs(int[] nums) {
int n=nums.length;
boolean[] check=new boolean[n];
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(gcd(nums[i], nums[j])>1){
check[i]=true;
check[j]=true;
}
}
}
for(int i=0;i<n;i++){
if(!check[i]) return false;
}
return true;
}
}
Metadata
Metadata
Assignees
Labels
No labels