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.
I don't understand why for test suite 4 :
a=[0 1 1 1 0 2 2 0 1 1 1 0];
y_correct = [1 1];
I expect y_correct = [1 1 1]
The idea seems to be to return the element that occurs in the longest run, or all such elements in case of a tie. In case 4 there are two longest runs, both with element 1.
Thanks Tim for the explanation . So as the vector [1 1 1] appears twice in test 4 with the unique value 1 , the result must be twice the unqiue value -> [ 1 1]. ok ok thanks again
Nice
It was not so easy...
What kind of solution is that?
that's a bug of Matlab Cody, the use of ! and regexp.
I don't know why Mathworks has it not corrected.
Can't understand a bit of this code.
i'd really like to see a better solution that mine, one that uses difference equations..mine is size 129 and is just a control loop. Guess i've got to search in solution map.
218 Solvers
Test if two numbers have the same digits
155 Solvers
Given a 4x4 matrix, swap the two middle columns
366 Solvers
Calculate the Number of Sign Changes in a Row Vector (No Element Is Zero)
128 Solvers
1400 Solvers