### ankit_verma's blog

By ankit_verma, history, 2 months ago,

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

• -9

 » 2 months ago, # | ← Rev. 2 →   0 ..updated
 » 2 months ago, # |   0 can you provide the submission link, it is difficult to read.
•  » » 2 months ago, # ^ | ← Rev. 2 →   0 submission Link-https://leetcode.com/playground/gWN5kxkZ
•  » » » 2 months ago, # ^ |   0 page not found, I cannot access the link.
•  » » » » 2 months ago, # ^ |   0 sorry for that now please check again...
 » 2 months ago, # | ← Rev. 7 →   0 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.
•  » » 2 months ago, # ^ |   0 ThankU for Your Approach I am trying this Now
 » 2 months ago, # |   0 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.
•  » » 2 months ago, # ^ |   0 So just pass the string as pass by reference.
•  » » » 2 months ago, # ^ |   0 Yes...I Got Accepted ThnkU