Watch tutorials and explanations by expert teachers that walk through solving this problem.
NeetCode
Inside code
Nick White
Techdose
Greg Hogg
Timothy H Chang
Algorithms Made Easy
Persistent Programmer
Solve more problems to master this pattern