FastPrepUnion of Two Arrays
Problems/Union of Two Arrays

Union of Two Arrays

Microsoft logoMicrosoft● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The round is not named in the review. It describes one interview for a Microsoft software engineering internship. The review lists an array-union question by name only, with no input or rules, next to a question on designing an experiment that compares two variants.

The review gives no rule for repeated values, order or limits. Here the answer lists each value that appears in either array exactly once, in increasing order, and each array has 1 to 5000 values from -10^5 to 10^5.

Our version is about 80% the same as the reported question.

Given two integer arrays nums1 and nums2, return their union: every value that appears in at least one of the arrays, listed once, in increasing order.

The input arrays are not necessarily sorted and may contain repeated values.

Function

unionOfArrays(nums1: int[], nums2: int[]) → int[]

Examples

Example 1

nums1 = [3,1,3,7]nums2 = [7,2,1]return = [1,2,3,7]

The values that appear in at least one array are 1, 2, 3 and 7. Each is listed once, in increasing order, even though 3, 1 and 7 appear more than once.

Example 2

nums1 = [5,5]nums2 = [5]return = [5]

Only the value 5 appears, so the union is [5].

Example 3

nums1 = [-2,0]nums2 = [4,-2,9]return = [-2,0,4,9]

The values are -2, 0, 4 and 9. Negative values sort before 0.

Constraints

  • 1 <= nums1.length, nums2.length <= 5000
  • -10^5 <= nums1[i], nums2[i] <= 10^5

More Microsoft Onsite Interview questions

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
  • Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Count Cross-Array Target-Sum PairsVisa · OAVisa interview questions
  • Disjoint Target-Sum TripletsAmerican Express · PHONE SCREENAmerican Express interview questions
  • Efficient TeamsExpedia · OAExpedia interview questions
  • Merge Sorted ArrayDP World · ONSITE INTERVIEW
  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Merge Two Arrays Into Sorted OrderNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Sparse Vector Dot Product from TuplesMeta · ONSITE INTERVIEWMeta interview questions
  • Rank Transform an ArrayAgoda · ONSITE INTERVIEWAgoda interview questions
  • Deduplicate Logs: Keep FirstGoogle · ONSITE INTERVIEWGoogle interview questions
  • Loyal Customers by Two-Day Product VarietyAmazon · ONSITE INTERVIEW

Interview reports that mention this question

  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[] unionOfArrays(int[] nums1, int[] nums2) {
        // Write your code here.
    }
}
Checking account…