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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:51:41+00:00 2026-05-27T09:51:41+00:00

Given two arrays int arr1[n] int arr2[m] where n > m Need to write

  • 0

Given two arrays

int arr1[n]
int arr2[m]

where n > m

Need to write a union of two arrays into one.

For example, if the input arrays are:

   int arr1[] = {1, 3, 4, 5, 7}
   int arr2[] = {2, 3, 5, 6}

Then program should create new array Union as {1, 2, 3, 4, 5, 6, 7}

Implementation can be in C# or Java.

In order to solve it first of all need to to sort the arrays using Merge Sort
and then do the union

I looked in the net but did not find the elegant way . Every code that I looked
was full of IF’s.

Please advice what is the most quick and elegant way to do it

  • 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-27T09:51:42+00:00Added an answer on May 27, 2026 at 9:51 am

    You are correct that merging the two lists as is done in Merge Sort is the most efficient thing to do. This assumes that the two lists are already sorted, as in your example. Here is an example of how to implement merge:

    function merge(left,right)
        var list result
        while length(left) > 0 or length(right) > 0
            if length(left) > 0 and length(right) > 0
                if first(left) ≤ first(right)
                    append first(left) to result
                    left = rest(left)
                else
                    append first(right) to result
                    right = rest(right)
            else if length(left) > 0
                append first(left) to result
                left = rest(left)
            else if length(right) > 0
                append first(right) to result
                right = rest(right)
        end while
        return result
    

    From here, simply do not include repeats in the final output.

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

Sidebar

Related Questions

Given an array a and two other int variables, k and temp, write a
Given two sorted arrays: A and B . The size of array A is
Given an array like {one two, three four five}, how'd you calculate the total
Given two 3D vectors A and B, I need to derive a rotation matrix
Given two colors and n steps, how can one calculate n colors including the
Given the arrays: int canvas[10][10]; int addon[10][10]; Where all the values range from 0
Given the need to loop up to an arbitrary int value, is it better
You are given two sorted integer arrays, which have some common integers. Any common
In a C++ program I have two classes (structs) like struct A { int
The exercise says Make a function with parameters two int arrays and k which

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.