Longest run of consecutive numbers - MATLAB Cody - MATLAB Central

Problem 672. Longest run of consecutive numbers

Difficulty:Rate

Given a vector a, find the number(s) that is/are repeated consecutively most often. For example, if you have

a = [1 2 2 2 1 3 2 1 4 5 1]

The answer would be 2, because it shows up three consecutive times.

If your vector is a row vector, your output should be a row vector. If your input is a column vector, your output should be a column vector. You can assume there are no Inf or NaN in the input. Super (albeit non-scored) bonus points if you get a solution that works with these, though.

Solution Stats

20.59% Correct | 79.41% Incorrect
Last Solution submitted on May 13, 2025

Problem Comments

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
2
4
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Group

Basics - Cell Arrays Image
Basics - Cell Arrays
  • 10 Problems
  • 1277 Finishers

Problem Recent Solvers5961

Community Treasure Hunt

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

Start Hunting!
Go to top of page