sir my approach is too messy even I have passed all the test case I am not able to understand it can u suggest me another way to do this question
Double side arrow
but sir still I am not able to understand question
you have use this approach
read this
Approach:
- In the given example, N=7 and the number of ROWS is 7.
- VERTICALLY, the pattern GROWS till ROW=N/2 and SHRINKS afterwards.
- ROW 1 has 4 ” “(SPACE) characters and then a value.
- The number of SPACE characters decreases whereas NUMERALS increase in count in each successive row.
- Also, note that the 1st value of the number placed in each row is the same as the number of the row.
- Also HORIZONTALLY the pattern has NUMERALS, then SPACES and NUMERALS afterwards.
from this which thing you don’t understand?
i will explain you
1 Like
yes sir I understood this much I am not able to understand how to create space in between the pattern like 2 row has 1 space , 3 row has 5 then 7. can u expain that
1
2 1 1 2
3 2 1 1 2 3
4 3 2 1 1 2 3 4
3 2 1 1 2 3
2 1 1 2
1
see the pattern
there are 2i+1 spaces in b/w nos where i is row no
for i=0 spaces=1
i=1 space=3
i=2 spaces=5 and so on…
so you can write like
for(int j=0;j<2*i+1;j++){
cout<<" ";
}
sir for I=0 we are taking second row and I=1 we are taking 3 row??
okay then use
2*i-1 this will also work
for(int j=0;j<2*i+1;j++){
cout<<" ";
}