PowerShell v3+, 62 bytes
param($n)($n[(0..$n.count|?{0-in$n[$_-1],$n[$_+1]})]|sort)[-1]
A bit longer than the other answers, but a nifty approach.
Takes input $n
. Then loops through the indices 0..$n.count
, uses the Where-Object
(|?{...}
) to pull out those indices where the previous or next item in the array is 0
, and feeds those back into array slice $n[...]
. We then |sort
those elements, and take the biggest [-1]
.
Examples
PS C:\Tools\Scripts\golfing> @(1,4,3,6,0,3,7,0),@(9,4,9,0,9,0,9,15,-2),@(-4,-6,-2,0,-9),@(-11,0,0,0,0,0,-12,10)|%{""+$_+" --> "+(.\largest-number-beside-a-zero.ps1 $_)}
1 4 3 6 0 3 7 0 --> 7
9 4 9 0 9 0 9 15 -2 --> 9
-4 -6 -2 0 -9 --> -2
-11 0 0 0 0 0 -12 10 --> 0
PS C:\Tools\Scripts\golfing> @(0,20),@(20,0),@(0,7,20),@(7,0,20),@(7,0,6,20),@(20,0,6)|%{""+$_+" --> "+(.\largest-number-beside-a-zero.ps1 $_)}
0 20 --> 20
20 0 --> 20
0 7 20 --> 7
7 0 20 --> 20
7 0 6 20 --> 7
20 0 6 --> 20
You should add a test case like the 4th one, but where the result is negative (there are positive numbers in the list). – mbomb007 – 2016-09-21T15:11:13.370
I was going to try this in Retina, but then I noticed there are negatives. Retina hates negatives. – mbomb007 – 2016-09-21T15:12:19.533
2Don't let retina dictate what you can and cannot do. Take charge, you're the boss! – Stewie Griffin – 2016-09-22T10:26:31.083