Hollow Rhombus: In this question, my code is printing the right output for all the inputs I have tried in it. But when I’m trying to submit it shows the Wrong Answer. Please help me with the code!

#include
using namespace std;
int main(){
int N;
cin>>N;
if(N<=20){
for(int i=1;i<=N;i++){
for(int j=N-i;j>=0;j–)
cout<<" “;
for(int x=1;x<=N;x++){
if(i==1||i==N)
cout<<”";
else{
if(x==1||x==N)
cout<<"
";
else
cout<<" ";
}
}
cout<<endl;
}
}
return 0;
}

hi… pls save ur code on ide and send…

Hi… so ur code is failing test cases because
image
here u can see ur code is printing an extra space in the last line at starting…

just make this change
for(int j=N-i-1;j>=0;j–)

u were starting ur j loop from N-i… just make it N-i-1

OH, okay I got it now!
Thank you so much for the help!! :stuck_out_tongue:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like