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 7034503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:11:38+00:00 2026-05-28T01:11:38+00:00

What is the best approach to solve the following problem in Java? There are

  • 0

What is the best approach to solve the following problem in Java?
There are 3 two-dimensional arrays that have equal number of rows and columns:

Array1:
[1]: {1, 2, 3}
[2]: {2, 2, 4}
[3]: {1, 1, 1}

Array2:
[1]: {1, 2, 0}
[2]: {1, 2, 3}
[3]: {1, 0, 1}

Array3:
[1]: {1, 1, 1}
[2]: {1, 2, 3}
[3]: {1, 0, 1}

I need to find out the indexes of rows that exist in all arrays. In the above example the answer should be: [1],[2],[2]

Array1
[1]: {1, 2, 3}

Array2:
[2]: {1, 2, 3}

Array3:
[2]: {1, 2, 3}

UPDATE: Is there any built-in function to do this? Or is the FOR loop the unique solution?

  • 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-05-28T01:11:39+00:00Added an answer on May 28, 2026 at 1:11 am

    I would do the following:

    • Create a class that takes a row in the array and implements hashcode and equals.
    • Insert each row (wrapped in the above class) in the first two arrays into two HashMaps
    • for each row in the last array, determine if they exist in the HashMaps

    Edit #2, realized the mapping would need to be reversed.

    private Map<MyClass, Integer> map(int[] array){
      Map<MyClass, Integer> arrayMap = new HashMap<>();
      for (int i; i<array.length; i++)
            arrayMap.put(new MyClass(array[i]), i);
    }
    
    private mySearch(){
       int[] array1, array2, array3;
    
       Map<MyClass, Integer> map1 = map(array1);
       Map<MyClass, Integer> map2 = map(array2);
    
       for (int i=0; i<array3.lenght; i++){
          MyClass row = new MyClass(array3[i]);
          Integer array1Row = map1.get(row);
          Integer array2Row = map2.get(row);
    
          if (array1Row != null && array2Row != null){
             // Matching rows found
          }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best approach to calculating the largest prime factor of a number?
What is the best approach to build a small (but scalable) application that works
Guys I'm new to xml in Java. I have the following task. I need
Thinking of a way how to best approach the following design (pseudo C++ code):
Hi I have the following problem and I am trying to work out what
I am looking for an algorithm that will solve my problem in the most
I have a graph-theoretic (which is also related to combinatorics) problem that is illustrated
I'm trying to solve the group-wise max problem in LINQ. To start, I have
Suppose you have an application that consists of two layers: A: A data layer
What is the best approach to define additional data for typedef enums in C?

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.