Sort by

recency

|

409 Discussions

|

  • + 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());
        }
    }
    

    }

  • + 0 comments

    HashSet myhash = new HashSet(); for (int i = 0; i < t; i++) { myhash.add(pair_left[i]+"#"+pair_right[i]); System.out.println(myhash.size()); }

    it is right code ? but compiler show error me every time test case 5 failed