Given two arrays, find the maximum overlap - MATLAB Cody - MATLAB Central

Problem 95. Given two arrays, find the maximum overlap

Difficulty:Rate
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

40.64% Correct | 59.36% Incorrect
Last Solution submitted on May 09, 2025

Problem Comments

Solution Comments

Show comments
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
3

Group

Cody Challenge Image
Cody Challenge
  • 12 Problems
  • 507 Finishers

Problem Recent Solvers1627

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page