If I understand the assignment correctly, maybe you can use this as an outline:
y = -inf;
for i = 1:length(x)
if( nearzero )
y = max(y,x(i));
To write the code for nearzero, you will need to check if x(i-1) == 0 or if x(i+1) == 0. But you can't blindly do this, since this will not work for x(1) and x(end) because they are on the ends. So you will need to put in some checks to see if it is a start or end element to know which elements nearby you can check.