Longest Palindromic Substring Flashcards
1
Q
What are the inputs and outputs?
A
input: string
output: string of valid palindrome
2
Q
Is there an edge case?
A
Input is less than value of 1
3
Q
What is your approach?
A
- Create start and end variable
- Create expandAroundChar function that checks the left and right of a char to see if they match
- Create a for loop of s
- check for odd palindrome and even palindrome
- compare left and right then set new indexes for start and end variable if more than initial value
- return substring of start and end
4
Q
What is the time complexity?
A
O(n^2)
- iterating over each character is o(n)
- expandingAroundChar is o(n) because we expand outwards until we reach end of string
- since we have 2 potential centers(odd & even strings) it becomes O(n^2)
5
Q
What is the space complexity?
A
O(1)
- no data structures used