Now i am facing time limit exceeded

#include
using namespace std;
int main() {
int n;
cin>>n;
int arr[n];
int arr2[1000000];
for(int i=0;i<n;i++)
{
cin>>arr[i];

}
int max=arr[0];
for(int i=0;i<n;i++)
{
	if(arr[i]>max)
	{
		int temp=arr[i];
		max=arr[i];
		arr[i]=temp;
	}
}
for(int i=0;i<n;i++)
{
	arr2[arr[i]]++;
}
for(int i=0;i<=max;i++)
{
	if(arr2[i]>0)
	{
		for(int j=0;j<arr2[i];j++)
		{
			cout<<i<<" ";
		}
	}
}
return 0;

}

#include using namespace std; int main() { int n; cin>>n; int arr[n]; int arr2[1000000]; for(int i=0;i<n;i++) { cin>>arr[i]; } int max=arr[0]; for(int i=0;i<n;i++) { if(arr[i]>max) { int temp=arr[i]; max=arr[i]; arr[i]=temp; } } for(int i=0;i<n;i++) { arr2[arr[i]]++; } for(int i=0;i<=max;i++) { if(arr2[i]>0) { for(int j=0;j<arr2[i];j++) { cout<<i<<" "; } } } return 0; }

Hello @jatingarg17,

Please, from the next time share your code using Online Coding Blocks IDE: https://ide.codingblocks.com
The way you have sent it is introducing many syntax errors to it.
Steps:

  1. Paste your code in IDE.
  2. Save it there.
  3. Share the URL generated.

Now, coming back to your problem.
I have modified your code:


Please, refer to the comments for better understanding.

Hope, this would help.
Give a like if you are satisfied.