Problem 672. Longest run of consecutive numbers
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
I have this array as I counted the times it repeats. However, can someone give me a command to pull out the max values with the number to the left? Any advise? The first value in column on the right top doesn't matter as it should always be 1. I try the max command it only shows the max value of 3...:
Great problem. Thank you.
Is there a way to test output without submitting?
I really liked this one
This was fun.
The problem should specify that if the same number repeats the longest run of consecutive numbers more than once, it must be repeated in the output.
I like this problem, it very fun
Should be more specific about the expected output, the solution checkers expect the output of numbers to be listed in the order of when they occurred in the sequence and also if the same number repeats in the sequence (with the largest run again) it needs to be repeated in the output. Both of these criteria broke my solution.
that was the first matlab problem i solved by myself, i'm so excited:)
to be honest, though I solved the problem ,I didn't quite understand how to improve my code. I mean, the top of the solutions seemed quite strange to me .why by doing that the size would be smaller?
Hi 昱树 何,
In Matlab Cody, size of a solution is calculated by various factors, one of them being the number of variables used. However, the top solution in this problem (and in many others as well) exploit the use of regexp to gain a lower solution size. This was done because earlier the scoring was based on your solution size, which has now been changed to a fixed 10 points.
Hope this helps.
took a while doing this but overall good question. I got stuck in the last test case.
hm, I don't think the assertion in test 4 is intuitively correct. The problem asks for the number(s) that have the longest consecutive repetitions in the input vector. So there can be multiple numbers having the longest runs (of equal size), but if all those numbers are the same, as in [1 1 2 1 1], surely the answer is "1", not "1 and 1".
I can only imagine that's what the implementation turned out to produce and instead of fixing the implementation to fit the problem, the tests was introduced to check for exactly that output ;)
Which is fine, you'll always have clients in real life that say they want something and when you roll it out they meant something different, it just bothers me that my nice solution doesn't work because of this 😂
The problem specifically states that column and row vectors must be supported, but then doesn't have a test for this. I'd suggest changing at least one of the tests to use a column vector.
Or maybe add one test where it is asserted that `longrun(a) == transpose(longrun(transpose(a)))`
Repeated consecutively makes the problem more difficult otherwise, we can use unique and histcounts to solve this quickly.
Not as difficult as it seems.
Solution CommentsShow comments
Problem Recent Solvers4464
Who is the smartest MATLAB programmer?
More from this Author80
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!