Skip to content

Bug Report for greatest-common-divisor-traversal #4794

@Shivam140802

Description

@Shivam140802

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions