Find the longest sequence of 1's in a binary sequence. - MATLAB Cody - MATLAB Central

Problem 15. Find the longest sequence of 1's in a binary sequence.

Difficulty:Rate

Given a string such as

 s = '011110010000000100010111'

find the length of the longest string of consecutive 1's. In this example, the answer would be 4.

Example:

 Input  x = '110100111'
 Output y is 3

Solution Stats

39.59% Correct | 60.41% Incorrect
Last Solution submitted on May 11, 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

CodeCrunch 1 Image
CodeCrunch 1
  • 11 Problems
  • 10 Finishers

Problem Recent Solvers6452

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