June-Lunchtime-2020:Getting WA for this soultion? #INCRDEC

#include <stdio.h>
#include <stdlib.h>

int main()
{
int N[100005], T, n;
scanf("%d", &T);
while (T- -)
{
scanf("%d", &n);
N[n];
int a[200005] = {0}, max = 0, flag = 1;
for (int i = 0; i < n; i++)
{
scanf("%d", &N[i]);
if (max < N[i])
max = N[i];
a[N[i]]++;
if (a[N[i]] > 2)
{
flag = 0;
}
}
if (flag && a[max] < 2)
{
printf(“Yes\n”);
for (int i = 0; i < 200004; i++)
{
if (a[i] != 0)
{
printf("%d “, i);
a[i]–;
}
}
for (int i = 200004; i > 0; i–)
{
if (a[i] != 0)
{
printf(”%d “, i);
a[i]–;
}
}
printf(”\n");
}
else
{
printf(“No\n”);
}
}

return 0;

}

Hey ,

Why are you printing i here ?

Edit : You are right , sorry , got confused

YES

NO

  • The second line should contain N space-separated integers ― the elements of your permuted sequence.
    it is asked to print.

The actual problem was with yes and No but now its resolved. Solution AC.
Thanks a lot buddy.

1 Like