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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:57:12+00:00 2026-06-02T14:57:12+00:00

I need to get the unique value from 2 int arrays Duplicate is allowed

  • 0

I need to get the unique value from 2 int arrays

Duplicate is allowed

There is just one unique value

like :

int arr1[3]={1,2,3};
int arr2[3]={2,2,3};

and the value i want to get is :

int unique[]={1}

how can i do this?
im already confused in my ‘for’ and ‘if’
this was not homework

i know how to merge 2 arrays and del duplicate values

but i alse need to know which array have the unique value

plz help me 🙂

and here is some code i did

int arr1[3]={1,2,3}
int arr2[3]={2,2,3}
int arrunique[1];
bool unique = true;
for (int i=0;i!=3;i++)
{

    for (int j=0;j!=3;j++)
    {
    if(arr1[i]==arr2[j])
    {
        unique=false;
        continue;
    }
    else 
    {
        unique=true;
    }
if(unique)
{
arrunique[0]=arr1[i]
break;
}
}

cout << arrunique[0];
  • 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-02T14:57:14+00:00Added an answer on June 2, 2026 at 2:57 pm

    Assuming:

    • You have two arrays of different length,
    • The arrays are sorted
    • The arrays can have duplicate values in them
    • You want to get the list of values that only appear in one of the arrays
      • including their duplicates if present

    You can do (untested):

    // Assuming arr1[], arr2[], and lengths as arr1_length  
    int i = 0,j = 0, k = 0;
    int unique[arr1_length + arr2_length];
    
    while(i < arr1_length && j < arr2_length) {
       if(arr1[i] == arr2[j]) {
         // skip all occurrences of this number in both lists
         int temp = arr1[i];
         while(i < arr1_length && arr1[i] == temp) i++;
         while(j < arr2_length && arr2[j] == temp) j++;
       } else if(arr1[i] > arr2[j]) {
         // the lower number only occurs in arr2
         unique[k++] = arr2[j++]; 
       } else if(arr2[j] > arr1[i]) {
         // the lower number only occurs in arr1
         unique[k++] = arr1[i++]; 
       }     
    }
    
    while(i < arr1_length) {
       // if there are numbers still to read in arr1, they're all unique
       unique[k++] = arr1[i++];
    }
    while(j < arr2_length) {
       // if there are numbers still to read in arr2, they're all unique
       unique[k++] = arr2[j++];
    }
    

    Some alternatives:

    • If you don’t want the duplicates in the unique array, then you can skip all occurrences of this number in the relevant list when you assign to the unique array.

    • If you want to record the position instead of the values, then maintain two arrays of “unique positions” (one for each input array) and assign the value of i or j to the corresponding array as appropriate.

    • If there’s only one unique value, change the assignments into the unique array to return.

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

Sidebar

Related Questions

I would like to know if its possible to get 2 sums from one
I need to get the unique name from a string and concatenate with an
Just need get some vals located in application.ini(main ini) in the Controller plugin I
I need get all items these have no categories int? categoryId = null; var
I have two tables with a weak relation. I need get a text value
I need to get the unique USB ID (not a Volume serial number )
the id filed is a Integer(from 1 to Integer.MAX_VALUE,unique), I don't need range searches
I'm trying to get data from one database and put it in the format
I need a SQL query for getting the lowest value of score for unique
I'm working with C#.net developing applications for windows mobile 6, and i need get

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.