Sort by

recency

|

410 Discussions

|

  • + 0 comments

    The part that says (a,b) is not the same as (b,a) is not correct. The solution counts ni kg and kg ni as the same. This fixes Test 5. The test case is not correct, or the task definition.

  • + 0 comments

    Please fix Test 5. The Expected results are not correct. It goes wrong at line 191.

  • + 0 comments
        HashSet<String> hashSet = new HashSet<String>();
        for (int i = 0; i < t; i++) {
            String pair;
            if (pair_left[i].compareTo(pair_right[i]) < 0) {
                pair = pair_left[i] + " " + pair_right[i];
            } else {
                pair = pair_right[i] + " " + pair_left[i];
            }
    
            hashSet.add(pair);
            System.out.println(hashSet.size());
        }
    
  • + 0 comments

    Solved case5: //Write your code here HashSet pairs = new HashSet<>();

    for (int i = 0; i < t; i++) {
        // Create unique pair representation
        String pair = pair_left[i] + " " + pair_right[i];
        // Add to HashSet (automatically handles duplicates)
    
        // Print current size after each addition
        String inverse_pair  =  pair_right[i] + " " + pair_left[i];
            if(!pairs.contains(inverse_pair)) 
            pairs.add(pair);
            System.out.println(pairs.size());
    }
    
  • + 0 comments

    any one help ee to solve the error in this code 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();
        }
    
        // Write your code here
        HashSet<String> pairs = new HashSet<>();
    
        for (int i = 0; i < t; i++) {
            // Create unique pair representation
            String pair = pair_left[i] + " " + pair_right[i];
            // Add to HashSet (automatically handles duplicates)
            pairs.add(pair);
            // Print current size after each addition
            System.out.println(pairs.size());
        }
    }
    

    }