Longest Palindromic Subsequence
Recognize the pattern
Brute force idea
A straightforward first read of Longest Palindromic Subsequence is this: Generate all subsequences and check which are palindromes. Exponential. That instinct is useful because it follows the prompt literally, but it usually keeps revisiting work the problem is begging you to organize.
Better approach
The deeper shift in Longest Palindromic Subsequence is this: The LPS of string s equals the LCS of s and reverse(s). Use the standard LCS DP. Alternatively, interval DP: dp[i][j] = LPS length of s[i.j]. If s[i]==s[j], dp[i][j] = dp[i+1][j-1] + 2. Else max(dp[i+1][j], dp[i][j-1]). Once you hold onto the right piece of information from moment to moment, the problem feels less like trial and error and more like following a shape that was there all along.
Key invariant
At the center of Longest Palindromic Subsequence is one steady idea: A palindrome reads the same forwards and backwards. The longest palindromic subsequence is equivalent to the longest common subsequence between the string and its reverse — characters that appear in matching order from both ends. When you keep that truth intact, each local choice supports the larger solution instead of fighting it.
Watch out for
A common way to get lost in Longest Palindromic Subsequence is this: Confusing palindromic SUBSEQUENCE with palindromic SUBSTRING — subsequences don't need to be contiguous. The DP allows skipping characters. Most mistakes here are not about syntax; they come from losing track of what your state, pointer, or structure is supposed to mean.