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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:56:27+00:00 2026-05-24T22:56:27+00:00

I had 2 integer arrays, one original and one modified w.r.t the original array.

  • 0

I had 2 integer arrays, one original and one modified w.r.t the original array.
Elements can be added or removed from the original to convert it to the modified. My problem is, in the modified, I need to find out which elements are new, which elements are same, and which elements are not there w.r.t to the original array.

Given data:

arr1 = 3,2,1      //Original array
arr2 = 1,4,5      //Modified array by adding and/or removing elements

I need something like:

same = 1
removed = 2,3
added = 4,5

Obviously, I can write several nested for loops and find it out, but this would be too inefficient. I was wondering if there was be a better or efficient way to do it..
I am using Java.
This page kind of address a similar problem, but not sure if I can use it to solve my problem.

Any help would be appreciated.

  • 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-24T22:56:29+00:00Added an answer on May 24, 2026 at 10:56 pm

    You could go through each array once and obviously use a removal save iteration like a loop from the back of the array.

    int[] same
    for (int i = arr1.length; i >= 0; i--)
    {
        if(arr2.contains(i))
            same.add(i)
            arr1.remove(i)
    }
    for (int i = arr2.length; i >= 0; i--)
    {
        if(same.contains(i))
            arr2.remove(i)
    }
    

    Then arr1 will be the list of removed, arr2 will be added and same will be the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had this question: Given an unsorted array of positive integers and an integer
So I have an array from 0-4, that has 5 random integer values (ie
I rewrote the original radix sort algorithm for Python from Wikipedia using arrays from
I need to return an array of initialized objects from VB6 into C# using
I had used several ways to do some simple integer arithmetic in BASH (3.2).
I had a simple table: class test(Base): __tablename__ = 'test' id = Column(Integer, primary_key=True)
Had a good search here but can't see anything that gets my mind in
I have never had a need to do a random SELECT on a MySQL
Possible Duplicate: Integer summing blues, short += short problem I feel dumb that this
We had a piece of code in C in one class where we needed

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.