ARRAYS-INTERSECTION OF TWO ARRAYS- code passes sample case but fails all test cases

#include
#include <string.h>
using namespace std;

int main()
{
int n;
cin>>n;
char a[n],b[n];

for(int i=0;i<n;i++)
{
	cin>>a[i];
}

for(int i=0;i<n;i++)
{
	cin>>b[i];
}

cout<<"[";
for(int i=0;i<n;i++)
{
for (int j=0;j<n;j++)
{
if(a[i]==b[j])
{
cout<<a[i]<<","<<" " ;
b[j]=‘x’;
break;
}
}
}
cout<<"]";

return 0;

}

Can you share the Qn link ?

Hi Shagun,

There are two problems. You need to print the output array in sorted order and your code prints a comma at the end of last element. Try to remove these errors and in case you have any further doubts, let me know.

https://hack.codingblocks.com/contests/c/457/209

Hey Shagun! actually the output that your code is printing is not correct as it is printing comma after the last integer as well, so you need to fix these first and then while printing you must be aware of the thing of printing the integers in sorted order , for this you can maintain an another array in which you will be saving the intesection elements. And if you sort this now it will sort the array according to lexicographical order so you should take all array as integer arrray . So, rplace all character array with integer array you will get ur answer.
In case you feel any difficulty you can go through ur code . https://ide.codingblocks.com/#/s/14090

Bro, Can you please ,what is problem in this code this is only passing one test case

Problem Link:https://hack.codingblocks.com/app/contests/2049/173/problem

Code Link:https://ide.codingblocks.com/s/423373