Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8501965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:21:23+00:00 2026-06-11T01:21:23+00:00

I do have int pairs, i.e; (int ,int) 1) Given k such pairs, check

  • 0

I do have int pairs, i.e; (int ,int)

1) Given k such pairs, check if they are unique. i.e; size of the Set formed using k pairs is k ?
2) if the given k records are unique then store them in sorted order ( by x and resolve conflict by y)
3) Given n such sets of size k, create a set of sets.

Example of requirement 1 and 2
if k = 3

(100, 100) (110, 300) (120, 200) is a valid set and in sorted order.
(100, 100) (300, 200) (200, 300) is a valid set but not in sorted order.
(100, 100) (100, 200) (100, 200) is in valid set

Example of requirement 3
input:

(100, 100) (200, 300) (300, 200)
(100, 100) (200, 300) (300, 200)
(100, 100) (201, 300) (300, 200)

output:

(100, 100) (200, 300) (300, 200)
(100, 100) (201, 300) (300, 200)

This is the closest analogy to the real problem i am facing. I need to get this done in Java and i have never worked in java. I am a intermediate c++ programmer.

I could solve 1 and 2 via some ugly coding and sorting.
However i am not able to get 3. Below is what i could get so far for 3. The class pair implements comparable

(poc code)

import java.util.HashSet;
public class set {
    public static void main (String []args) {
        HashSet<Pair> s1 = new HashSet();
        s1.add(new Pair(10,10));
        s1.add(new Pair(10,10));

        HashSet<Pair> s2 = new HashSet();
        s2.add(new Pair(10,10));
        s2.add(new Pair(10,10));

        HashSet<HashSet<Pair>> s12 = new HashSet();
        s12.add(s1);s12.add(s2);
        for ( HashSet<Pair> hs : s12) {
            for (Pair p :  hs) {
                System.out.println(""+ p.toString());
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:21:25+00:00Added an answer on June 11, 2026 at 1:21 am

    Looks like you didn’t override equals and/or hashCode methods in Pair class.

    For example if your Pair class has the following structure :

    protected K value1;
    protected V value2; 
    

    You should implement equals and hashCode as(example) :

     public boolean equals(Object obj) {
        if (!(obj instanceof Pair))
            return false;
        Pair that = (Pair)obj;
        boolean result = true;
        if (this.getValue1() != null)
            result = this.getValue1().equals(that.getValue1());
        else if (that.getValue1() != null)
            result = that.getValue1().equals(this.getValue1());
    
        if (this.getValue2() != null)
            result = result && this.getValue2().equals(that.getValue2());
        else if (that.getValue2() != null)
            result = result && that.getValue2().equals(this.getValue2());
    
        return result;
    } 
    
    
    public int hashCode() {
        int result = value1 != null ? value1.hashCode() : 0;
        result = 31 * result + (value2 != null ? value2.hashCode() : 0);
        return result;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an unordered_map (in C++) that pairs an int with an object of
I have vector< pair<int, int>> myVec (N); I want to have all pairs initialized
I have an int array which has no elements and I'm trying to check
Given two floating-point numbers, I'm looking for an efficient way to check if they
I have store 111 million key-value pairs (one key can have multiple values -
Let's say I have int a() { /* Tons of code ....*/ return someInt;
I have an int property in my viewmodel that returns a custom class property.
I have an int and float array of length 220 million (fixed). Now, I
i have two int array of images , i have implemented it in grid
I have an int property @property(nonatomic) int stackTop; and when it gets synthesized, it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.