Save BPL

Bangladesh Premier League (BPL) is one the most prestigious cricket tournaments. Talented players fr…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

In problem save bpl I used a for loop of length 15 and got tle but in the same code I removed for loop and used string.substr() funtion and got accepted. Can someone explain why?
As far I know substr has O(length of substring) complexity. So both should be accepted .
I am sorry if my knowledge is wrong.

Here are the codes

Time Limit Exceed

for(int i=0;i<a;i++)
	{
	    string s1="";
	    for(int j=0;j<k;j++)
		s1.push_back(s[j+i]);
	    if(sel>s1)
		sel=s1;
	}

Accepted Code

for(int i=0;i<a;i++)
	{
	    string s1;
	   s1=s.substr(i,k);
	    if(sel>s1)
		sel=s1;
	}