Watch tutorials and explanations by expert teachers that walk through solving this problem.
NeetCodeIO
One Code Man
Programming Live with Larry
Elite Code
Solve more problems to master this pattern