8 Encoding of 1 x 2 x 2 x 2 x 1 (numbers here represent the possible ways we can fil each place ).
4 Encoding of 1 x 2 x 2 x 1 x 0 (last is filled with zero so 2nd last has got 1 choice only)
4 Encoding of 0 x 2 x 2 x 1 x 1 (first is filled with zero so 2nd has got 1 choice only)
2 Encoding of 0 x 1 x 2 x 1 x 0 (first and last has 0 in that case we will have 2 options only 01110 and 01010).
8+4+4+2 = 18 hence the answer.
Another naive way is to write all 32 numbers then job is easy just remove the ones which has more than 1 trailling and leading zeroes..that would give 18 possible strings..