Watch tutorials and explanations by expert teachers that walk through solving this problem.
NeetCode
Nick White
code Explainer
Hua Hua
Kumar Sanjeev
Code Nop
CodeSpace
Satyam Kumar
Solve more problems to master this pattern