getting tle for my code of NAME2??

Please help! How can I optimize my code so that I don’t get tle…

http://www.codechef.com/viewsolution/4553664

UPDATE: look my below comment for actual problem with the submission above

@singh_abhinav >> The way you iterate over the strings s1 ans s2 is causing you TLE(it isn’t the right way to iterate). You must also assign extra space(minimum 1 greater than required) for ‘\0’ character to be stored at the end of the strings when using char array (i have increased the size of the char arrays from 25000 to 25010). This ‘\0’ character can be used to check for the end of the string.

Changes i made in your code

  • increase the size of the char arrays.
  • modified the way to iterate over char arrays.

Link to the modified code > 4556715

But I have read somewhere that if you use pointer then you save time consumed during multiplication as the value of index i is multiplied to the size of an elementary data type and added to the base address of the array to calculate the address of array[i]…

moreover, my previous submissions’ codes were just like yours but its just that i was using for loop???

You may be correct, but i didn’t look into it. however i tried another modification to your original TLE submission, which ran in 0.19 secs. whereas my previous modification ran in 0.22 secs. So there seems to a minor increment in speed.

Here is the link to newly modified code 4557164 (problem with your submission is you are calculating the length of strings every time you execute the while loops, which is costly. so i calculated them once before entering into while loops and stored them in variables l1 and l2).

thankyou so much! i got that since i was calculating length each time i was getting tle

//