Union of Two Arrays
Updated
Problem statement
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