Find duplicate number from a vector of size n + 1 containing numbers from 1:n - MATLAB Cody - MATLAB Central

Problem 58663. Find duplicate number from a vector of size n + 1 containing numbers from 1:n

Difficulty:Rate
From a given vector of size n + 1, return the duplicate number.
Constraints
The vector can only contain numbers from 1 to n inclusive
Only 1 number is duplicate.
Example -
x = [1 2 3 3]
The size of the vector is 4. Therefore n = 3 and it contains numbers from only 1 to 3 (inclusive). However there is just 1 duplicate number which is 3.
Return the value 3

Solution Stats

75.0% Correct | 25.0% Incorrect
Last Solution submitted on Jan 26, 2025

Solution Comments

Show comments
Registration Now Open for MathWorks AUTOMOTIVE CONFERENCE 2025
...
Hello Community, We're excited to announce that registration is now open for the...

Problem Recent Solvers18

Suggested Problems

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