Problem 95. Given two arrays, find the maximum overlap
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
Show
9 older comments
Shlomo Geva
on 17 Nov 2020
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.)
Vishrut
on 11 Jul 2022
Good Question
邵俊淞2353280
on 1 Aug 2024
difficult
Solution Comments
Show commentsGroup

Tough Stuff
- 19 Problems
- 7 Finishers
- Make a function that returns its own character count
- love is an n-letter word
- Reverse Boggle
- Cumulative maximum of an array
- Pattern Recognition 3 - Variable Unit and Array Length (including cell arrays)
- Cumulative minimum of an array
- Find the Final State of an Abelian Sandpile
- Decimation - Optimized for speed
- Construct a "diagAdiag" matrix
- Find vampire numbers
- Math with Roman Numerals
- Find similar sequences
- Given two arrays, find the maximum overlap
- Some Assembly Required
- N-Dimensional Array Slice
- Find the stride of the longest skip sequence
- Create initial basic feasible solution for transportation problems -Minimum Cost Method
- Numbers spiral diagonals (Part 2)
- Find the biggest empty box
Problem Recent Solvers1609
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!