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
nice
good idea
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?
cool
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...
smart solution.
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.
1516 Solvers
1090 Solvers
348 Solvers
693 Solvers
494 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!