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.
importjava.util.*;publicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannerscanner=newScanner(System.in);Set<String>uNames=newHashSet<>();intcount=scanner.nextInt();for(intii=0;ii<count;ii++){Stringname1=scanner.next();Stringname2=scanner.next();// This is wrong in the problem statement for "Test case 5" where// (a,b) is the same as (b,a)// addressing this symmetry hereif(!uNames.contains(name1.concat(" ").concat(name2))&&!uNames.contains(name2.concat(" ").concat(name1))){uNames.add(name1.concat(" ").concat(name2));}System.out.println(uNames.size());}scanner.close();}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Hashset
You are viewing a single comment's thread. Return to all comments →