How to resolve time limit exceed error from my program



include <iostream>
#include <algorithm>
using namespace std;
int main()
int n;
int s[n];
for(int k=0;k<n;k++)
for(int m=0;m<n;m++
return 0;

I can’t understand why it is giving time limit exceed and which sorting algorithm does sort(s,s+n) uses and what’s is complexity ?? plz also suggest me some other algo to reduce complexity of my program!!


It’s getting TLE due to slower I/O. Using scanf and printf this solution will get AC. Accepted code

This problem can also be solved using counting sort in O(n) time.
C++ implementation

scanf printf faster than cin cout

STL Sort algorithm


Can anyone please explain me why it is giving TIME LIMIT EXCEEDED ?


Post a link to your code instead of pasting the entire code here.


Okk dude!!


Thanks finally get my code accepted!!


Why i getting code accepted in this case
and not in that case due to time limit exceeded although these are same
Plz help me!!


@chaman_amit If you got the answer for your question,then you should mark it as the correct answer,so that it won’t appear in unanswered questions. :slight_smile:


I won’t find any option to mark as correct answer , plz tell me so i ll do that!!