Two more tests:
1. Input x = [-4 -2 0 -4 -1 0]
Output y is -1.
2. Input x = [-9 -3 0 0 -5 0 -2 -1]
Output y is -2.
Good comment, Gaik. A lot of solutions (including mine) will break with two consecutive zeros.
Why: "Input x = [-9 -3 0 0 -5 0 -2 -1] Output y is -2."???
Output should be 0. It doesn't say anywhere that the number adjacent to a zero must be nonzero!
This was challenging
u can avoid loops friend..
Very interesting problem
I understand how this function works, but how did you know to use [1 0 1] for the convolution?
Quiet hard, but satisfying! :)
It is really cool to see someone has the exact chain of thoughts as you .... !!!
I believe size(x,2) is equivalent to length(x). Great solution though! Made me realize where I put in too much work.
Because of 2 bytes space charactor
Damn that's a lot higher score than I was expecting.
Trying to emulate imdilate.
Hi everyone. I realized this code is very large and cannot be run on this website because of the many loops that it has to go through. It works on matlab so if anyone could help me keep the general form of it but have it cut down in the number of loops that would be great. Thanks.
the imdilate function apparently can't be used... this is a clumsy clumsy workaround
This one was hard. Tried my best but couldn't get it shorter
I think the test suite needs a test for a = [0 0 0 0]. I passed with the above code but would not pass this case.
I ended up with the same logic, I'm glad I wasn't the only one.
It's a shame this is basically a verbose reworking of the imdilate function (which is not accessible for this challenge)
well, this looks a bit.. long?
I suppose overt is more at it. This will catch multiple consecutive zeros. I suppose I could have put comments too. Not to mention it's clocking 10^-6sec. Why do these Cody problems go by size isn't speed incredibly more important in computational programming.
regexp should really be banned from problems not related with word handling...
This solution gives the wrong value if the largest value is at the end of the vector. For example for x = [1 0 2 0 3] it returns 2 instead of 3.
Thanks for the tip!
It can handle adjacent zeroes.
No way that the leading solution is the least complex one! The rating function is questionable.
Fails when the max value output should be negative and the last value of the input vector is zero, e.g. a = [5 4 -1 0 -2 0 -5 0]. Should return -1, but returns 0.
this should work
Nice! It's quite clever to put the front and rear in pairs.
Peter's comment about Solution 20356 appears to apply here as well.
This solution gives the wrong value if the largest value is at the end of the vector, for example for x = [1 0 2].
It's wrong with the input [0 9 0].
Who Has the Most Change?
Remove all the words that end with "ain"
Scoring for oriented dominoes
Find the largest value in the 3D matrix
Generate a NaN...on purpose
Make a checkerboard matrix
Find the palindrome
Remove any row in which a NaN appears
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office