8 kyu

Merge two sorted arrays into one

24,128 of 39,100Y.y

Description:

You are given two sorted arrays that contain only integers. These arrays may be sorted in either ascending or descending order. Your task is to merge them into a single array, ensuring that:

  • The resulting array is sorted in ascending order.

  • Any duplicate values are removed, so each integer appears only once.

  • If both input arrays are empty, return an empty array.

No input validation is needed, as both arrays are guaranteed to contain zero or more integers.

Examples (input -> output)

* [1, 2, 3, 4, 5], [6, 7, 8, 9, 10] -> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

* [1, 3, 5, 7, 9], [10, 8, 6, 4, 2] -> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

* [1, 3, 5, 7, 9, 11, 12], [1, 2, 3, 4, 5, 10, 12] -> [1, 2, 3, 4, 5, 7, 9, 10, 11, 12]

Happy coding!

Fundamentals
Arrays

Stats:

CreatedFeb 7, 2017
PublishedFeb 7, 2017
Warriors Trained52490
Total Skips2213
Total Code Submissions114971
Total Times Completed39100
JavaScript Completions24128
Python Completions12416
Ruby Completions996
COBOL Completions11
C# Completions817
D Completions16
Rust Completions446
Go Completions814
Scala Completions43
CoffeeScript Completions11
Prolog Completions12
Total Stars390
% of votes with a positive feedback rating93% of 3382
Total "Very Satisfied" Votes2948
Total "Somewhat Satisfied" Votes362
Total "Not Satisfied" Votes72
Total Rank Assessments113
Average Assessed Rank
7 kyu
Highest Assessed Rank
1 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • Y.y Avatar
  • suic Avatar
  • anter69 Avatar
  • donaldsebleung Avatar
  • Blind4Basics Avatar
  • rowcased Avatar
  • metagn Avatar
  • ZED.CWT Avatar
  • a.kozhanov Avatar
  • hobovsky Avatar
  • stellartux Avatar
  • ejini战神 Avatar
  • akar-0 Avatar
  • dfhwze Avatar
  • KayleighWasTaken Avatar
Ad