Interland Interview Question

pattern-printing program and explain my logic