I’m wondering which is better:
learning common algorithms first and then solving problems, or learning how to think about algorithms while solving problems.
I guess I’ll find out by doing both.
Solved another problem today.
As usual, my first approach turned out to be more complicated than necessary.
But I managed to find a simpler solution again.
Today, I solved LPS.
At first, I tried to solve it using LCS by reversing the string and comparing it with the original. But that approach didn't work.
Then I realized that expanding around the center was simpler. My solution is O(n²), but it's simple and intuitive.
Solved a Sliding Window problem today.
I came up with an O(n²) solution and tried to avoid unnecessary repeated searches.
But I learned that avoiding duplicate searches doesn't necessarily make a solution O(n).
The key was to keep track of the last position of each character.