At most one leading and trailing 0 means that the number of zeroes in the beginning or the end of the string should be less than or equal to one. This is better understood with the help of an example.
01xx1 is a string of length 5 with one leading 0 and no trailing 0
1xx10 is a string of length 5 with no leading 0 but with one trailing 0
01x10 is a string of length 5 with one leading 0 and with one trailing 0
1xxx1 is a string of length 5 with neither a leading 0 nor a trailing 0
Here x indicates that the value can be either 0 or 1.
All cases other than those of the type above will be not be included in the 5 bit codeword.
Let's see such an example:
00110 here we have 2 leading 0's therefore this cannot be included in the codeword.
similarly in 11100 we have two trailing zeroes hence this cannot be included in the 5 bit codeword.
The actual answer of the question will be :
01xx1: We'll have 2 x 2=4 strings of this type
1xx10: We'll have 2 x 2=4 strings of this type
01x10: We'll have 2 strings of this type
1xxx1: We'll have 2 x 2 x 2=8 strings of this type
Therefore total no. of 5 bit codewords possible=4+4+2+8=18
Hope this clears your doubt