Sort by

recency

|

404 Discussions

|

  • + 0 comments

    test case number 5 has error.even code from the editorial can not pass it. please fix this.

  • + 0 comments

    Statement "That also implies (a,b) is not same as (b,a)." is not considered on test case 5, e.g. line 8 is "ni kg" and line 192 is "kg ni" but is not considered as a unique pair so it's not counted on expected output.

  • + 0 comments
    import java.io.*;
    import java.util.*;
    
    public class Solution {
    
        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 sc = new Scanner(System.in);
            int T = sc.nextInt();
            Set<String> dataset = new HashSet<String>();
            for(int i =0; i<T; i++){
                String A = sc.next();
                String B = sc.next();
                String pair = A + " " + B;
                String inverse_pair  =  B + " " + A;
                if(!dataset.contains(inverse_pair)) dataset.add(pair);
                System.out.println(dataset.size());
            }
        }
    }
    
  • + 0 comments

    PASSES ALL 6 TESTCASES

    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();
        }
    
    Set<String> set = new HashSet<>();
    for (int i = 0; i < t; i++) {
        String key = ( pair_left[i].compareTo(pair_right[i]) <= 0) ? ( pair_left[i]+ " " + pair_right[i]) : (pair_right[i] + " " +  pair_left[i]);
        set.add(key);
        System.out.println(set.size());
    }
    

    } }

  • + 1 comment

    The issue with test case 6 is how the problem is formulated:

    The original problem statement says that order matters, but test case 6 behaves as if order does not matter.

    public class Solution {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        Set<String> set = new HashSet<>();
        for (int i = 0; i < t; i++) {
            String a = sc.next();
            String b = sc.next();
            String key = (a.compareTo(b) <= 0) ? (a + " " + b) : (b + " " + a);
            set.add(key);
            System.out.println(set.size());
        }
    }
    

    }