Sort by

recency

|

368 Discussions

|

  • + 0 comments

    This passes all cases barr 5. Seems to be an issue with test case 5 as others have pointed out.

    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();
            }
    
    
    
            HashSet<String> strings = new HashSet<String>();
    
            // counter
            int lines = 0;
    
    
            for (int i = 0; i < t; i++){
                String concat = pair_left[i] + " " + pair_right[i];
                
                if(!strings.contains(concat)){
                    strings.add(concat);
                    lines++;
                }
                System.out.println(lines);
    }
    
  • + 0 comments

    The problem statement clearly says "That also implies (a, b) is not same as (b, a)", but following that causes test case 5 to fail. To "fix" my solution, I had to treat (a, b) and (b, a) as identical. Please update the problem to reflect this.

  • + 0 comments

    Is it possible to get confirmation that test 5 contains a bug/ faulty test data? i spent ages looking through it but i cannot figure out whats wrong. Some people seem to have found solutions to pass all tests though

  • + 1 comment

    I think the test case 5 is wrong. Does anybody have the same opinion? I am totally confused...

  • + 1 comment

    Passed Test

    import java.io.; 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();
        }
       // Use a HashSet to store unique pairs
        Set<String> uniquePairs = new HashSet<>();
    
        for (int i = 0; i < t; i++) {
            String[] pair = {pair_left[i], pair_right[i]};
            Arrays.sort(pair); // Sort the pair to ensure consistent ordering
            String sortedPair = pair[0] + "," + pair[1];
            uniquePairs.add(sortedPair);
            System.out.println(uniquePairs.size());
        }
    

    } }