We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public class Solution {
public static int dfs (int arr[][],boolean visited[],int k)
{
visited[k]=true;
int count =1;
for(int i=1;i
}
}
return count;
}
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int arr[][]= new int [2*n+1][2*n+1];
for(int i =0;i
}
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for(int i =1;i<=2*n;i++)
{
if(visited[i]==false)
{
int value= dfs(arr,visited,i);
if(value==1)
continue;
if(valuemax)
max = value;
}
}
System.out.println(min+" "+max);
}
}
//can u tell why only few test case are passing this code
please
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Components in a graph
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Solution { public static int dfs (int arr[][],boolean visited[],int k) { visited[k]=true; int count =1; for(int i=1;i }
} return count; } public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner in = new Scanner(System.in); int n = in.nextInt(); int arr[][]= new int [2*n+1][2*n+1]; for(int i =0;i } int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; for(int i =1;i<=2*n;i++) { if(visited[i]==false) { int value= dfs(arr,visited,i); if(value==1) continue; if(valuemax) max = value;
} //can u tell why only few test case are passing this code please