I am confused in this problem

confused in loop , how to apply

You need to code nested loops, the outer loop keeps track of the row number, the inner loops keeps track of a particular row, like how many stars and spaces to print according to pattern.
for first half:
for each row i no. of spaces = 2*i - 1 (except i=0, where no.of spaces = 0), no of stars = N-(no. of spaces)
similary for second half but in decreasing order
The pattern is very symmetrical so you have to do the work for only 1/4th of the pattern (upper left corner)

You can watch this video to get some idea.

test case fails in my code

Refer this https://ide.codingblocks.com/s/260682