# Can anyone help me out with my code to optimise this code.

Question Link-Question Link

Submission Link-Submission

# | User | Rating |
---|---|---|

1 | tourist | 3707 |

2 | Benq | 3672 |

3 | Radewoosh | 3655 |

4 | ksun48 | 3547 |

5 | jiangly | 3492 |

6 | Miracle03 | 3480 |

7 | ecnerwala | 3400 |

8 | maroonrk | 3385 |

9 | peehs_moorhsum | 3384 |

10 | sunset | 3338 |

# | User | Contrib. |
---|---|---|

1 | 1-gon | 216 |

2 | Um_nik | 190 |

3 | YouKn0wWho | 189 |

4 | sus | 183 |

5 | awoo | 182 |

6 | Errichto | 179 |

7 | tourist | 177 |

8 | -is-this-fft- | 172 |

9 | Radewoosh | 170 |

10 | maroonrk | 169 |

Question Link-Question Link

Submission Link-Submission

↑

↓

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Sep/25/2021 17:44:25 (f1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

..updated

can you provide the submission link, it is difficult to read.

submission Link-https://leetcode.com/playground/gWN5kxkZ

page not found, I cannot access the link.

sorry for that now please check again...

The maximum length of the input string is $$$1000$$$. You can use a brute-force algorithm to find the answer. Note that threre are $$$1, 2, 3, \ldots, N$$$ Substrings with lengths $$$N, N-1, N-2, \ldots, 1$$$, respectively. Start with Substring length $$$k = N$$$. If one of the $$$N-k+1$$$ Substrings with length $$$k$$$ is palindrome, then return it as the answer. Otherwise, decrement $$$k$$$ and repeat the previous step. If no palindrome Substring is found down to $$$k = 2$$$, then return any 1-letter Substring as the answer.

The following is my Kotlin implementation of the brute-force algorithm if you are interested.

KotlinLongest Palinrome Substring

ThankU for Your Approach I am trying this Now

In the recursive function, you are passing the string as pass by value. So if you pass it by value, for every call, the string is copied and adds an additional O(n) complexity.

So just pass the string as pass by reference.

Yes...I Got Accepted ThnkU