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