Problem 16. Return the largest number that is adjacent to a zero
This example comes from Steve Eddins' blog: Learning Lessons from a One-Liner
Write a function that takes a list or array of numbers as input and return the largest number that is adjacent to a zero.
Example:
Input x = [1 5 3 0 2 7 0 8 9 1 0] Output y is 8
This problem was originally posed by Greg Wilson of Software Carpentry.
Solution Stats
Problem Comments
-
4 Comments
Show
1 older comment
Geoff
on 8 May 2012
Good comment, Gaik. A lot of solutions (including mine) will break with two consecutive zeros.
Nicolae Preda
on 23 Sep 2013
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!
Kendale Greenidge-Bullock
on 8 Dec 2017
This was challenging
Solution Comments
Show commentsGroup

Cody Challenge
- 12 Problems
- 484 Finishers
- Add two numbers
- Find the sum of all the numbers of the input vector
- Quote Doubler
- De-dupe
- Cell joiner
- Remove all the words that end with "ain"
- Nearest Numbers
- Find state names that start with the letter N
- Word Counting and Indexing
- Given two arrays, find the maximum overlap
- It dseon't mettar waht oedrr the lrettes in a wrod are.
- Counting in Finnish
Problem Recent Solvers5413
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!