- My approach is to maintain two variables, leftSkip, and rightSkip.
- leftSkip = 0, if found any condition where value[left_index] != value[right_index]
- increment the left_index if leftSkip = 0 (one character needs to be removed, so skip the left character)
- increment the leftSkip then break(indicates more than one character needs to be removed)
- rightSkip = 0, if found any condition where value[left_index] != value[right_index]
- decrement the right_index if rightSkip = 0 (one character needs to be removed, so skip the right character)
- increment the rightSkip then break(indicates more than one character needs to be removed)
- check if leftSkip <=1 || rightSkip <=1, return true
- return false
Any other approach or any pointers on this approach is much appreciated
Course: https://www.educative.io/courses/grokking-coding-interview-patterns-cpp
Lesson: Valid Palindrome II - Grokking Coding Interview Patterns in C++