Sort by

recency

|

375 Discussions

|

  • + 0 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.

    import java.util.*;
    import java.text.*;
    import java.math.*;
    import java.util.regex.*;
    
    public class Solution {
    
     public static void main(String[] args) {
            Scanner s = new Scanner(System.in);
            int t = s.nextInt();
            String [] pair_left = new String[t];
            String [] pair_right = new String[t];
            
            for (int i = 0; i < t; i++) {
                pair_left[i] = s.next();
                pair_right[i] = s.next();
            }
    
    //Write your code here
        Set<String> uniquePairs = new HashSet<>();
            for (int i = 0; i < t; i++) {
                String pair1 = pair_left[i] + " " + pair_right[i];
                String pair2 = pair_right[i] + " " + pair_left[i];
                if(!uniquePairs.contains(pair1) && !uniquePairs.contains(pair2)){
                    uniquePairs.add(pair1);
                }
                System.out.println(uniquePairs.size());
            }
        }
    }[](https://)
    
  • + 0 comments

    There seems to be an inconsistency between the wording in the exercise and the expectation of Test Case 5, which seems to be a topic of frustration of multiple people here including myself.

    This is the wording in the exercise:

    Two pairs (a, b) and (c, d) are identical if a = c and b = d. That also implies (a, b) is not same as (b, a).

    Based on this requirement the pair "john tom" ≠ "tom john".

    However, Test Case 5 requires you that you actually treat (a, b) the same as (b, a), which is inconsistent with the wording in the exercise.

    Moving forward, to provide a consistent approach either the wording in the exercise is changed or Test Case 5 is adjusted accordingly.

  • + 0 comments

    public class Solution {

    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int i = sc.nextInt();
    
       HashSet<String> hs = new HashSet<>(i); 
       String c;
    
        while(i>0){
           c = sc.next();
           hs.add(c.toLowerCase());
              System.out.println(hs.size());
           i--;
        }
    }
    

    }

  • + 0 comments

    is something wrong with test case 5

    HashSet<String> set=new HashSet<>(t);
            
            for(int i=0;i<t;i++){
                
                if(set.add((pair_left[i] + "#" + pair_right[i]))){
                    
                    System.out.println(set.size());
                }else{
                    System.out.println(set.size());
                }
            }
    
  • + 0 comments
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    HashSet<String> set = new HashSet<>();
    IntStream.range(1, n+1).forEach(i -> {
    		set.add(Stream.of(scanner.next(), scanner.next())
    				.sorted(String::compareTo)
    				.collect(Collectors.joining(" ")));
    System.out.println(set.size());
    });
    scanner.close();