We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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());
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Hashset
You are viewing a single comment's thread. Return to all comments →
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];
} }