Watch tutorials and explanations by expert teachers that walk through solving this problem.
NeetCodeIO
Varun Gupta
SF
Mike the Coder
Programming Live with Larry
Hunter Macias
IB
Code Monger
Solve more problems to master this pattern