Given two (integer) arrays s1 and s2, create a new array s3 which is as short as possible and contains both arrays.
#1
s1 = [1 2 3 4 5]
s2 = [5 4 3 2]
s3 = [1 2 3 4 5 4 3 2]
There is guaranteed to be one best solution.
8/8/22 - New test case added (and solutions have been rescored)
#2
%courtesy of comments
s1 = [-1 -2 -3]
s2 = [-3 -1 -2]
s3 = [-3 -1 -2 -3]
Solution Stats
Problem Comments
12 Comments
Solution Comments
Show comments
Loading...
Group
Problem Recent Solvers1715
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
This would be improved by a richer test set to avoid solutions based on simple lookup of the test cases.
I think we can assume the entries are all positive integers, but it would be good if that was stated in the problem specification.
Definetely agree. Adding more tests in the test suite and rescoring the solutions will elmiminate solution under a score of 92
My 33 is a terrible solution. Please add more test cases.
Tim's 80 is very good and my 83 is also valid. Addition of a common random value at an end overlap will eliminate chicanery. v=randi(100) [1 2 3 v] [v 4 5].
Created legitimate size 72.
Added a few more tests. Thanks for the comments!
s1 = [3 1 4 1 5 9 2 6 5 3 5];
s2 = [9 2 6 5];
s3_correct = [3 1 4 1 5 9 2 6 5 3 5]; maybe is not correct ;-)
Problems 1 and 2 have alternate solutions:
1) [5 4 3 1 2 3 4 5]
2) [1 0 1 7 7 7 6 0 1]
Did I just solved this myself? Toughest for me so far. Thanks!!!
This did not make me sleep. Most difficult so far, took me some few hours lol.
minor point - the specification is poorly worded.
The test input/output is not strings, but rather integer arrays.
e.g.
s1 = [10 20 30 40 50]
rather than "10 20 30 40 50"
I suppose this problem was written before the introduction of strings to Matlab (2016b) and so it may not have been so ambiguous at the time. (although even back then I would have interpreted the word "string" to mean a character array.)
Good Question
difficult