Watch tutorials and explanations by expert teachers that walk through solving this problem.
NeetCode
Inside code
take U forward
Algorithms Made Easy
Programming Tutorials
Timothy H Chang
Ayushi Sharma
Solve more problems to master this pattern