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.
Here is my code that it can pass 5 test cases. I'm really disappointed of this problem. As you can see the problem tell us that "That also implies (a, b) is not same as (b, a)". But when you code with that constraint you can't pass test case 5. This makes me watse of time. So after doing this problem i gain experience that after 30 minutes if you can't pass all test cases just go to disussions and see how people solve the problem.
importjava.util.*;importjava.text.*;importjava.math.*;importjava.util.regex.*;publicclassSolution{publicstaticvoidmain(String[]args){Scanners=newScanner(System.in);intt=s.nextInt();String[]pair_left=newString[t];String[]pair_right=newString[t];for(inti=0;i<t;i++){pair_left[i]=s.next();pair_right[i]=s.next();}//Write your code hereSet<String>uniquePairs=newHashSet<>();for(inti=0;i<t;i++){Stringpair1=pair_left[i]+" "+pair_right[i];Stringpair2=pair_right[i]+" "+pair_left[i];if(!uniquePairs.contains(pair1)&&!uniquePairs.contains(pair2)){uniquePairs.add(pair1);}System.out.println(uniquePairs.size());}}}[](https://)
Java Hashset
You are viewing a single comment's thread. Return to all comments →
Here is my code that it can pass 5 test cases. I'm really disappointed of this problem. As you can see the problem tell us that "That also implies (a, b) is not same as (b, a)". But when you code with that constraint you can't pass test case 5. This makes me watse of time. So after doing this problem i gain experience that after 30 minutes if you can't pass all test cases just go to disussions and see how people solve the problem.
what is the solution though to pass test case 5?