Watch tutorials and explanations by expert teachers that walk through solving this problem.
NeetCodeIO
Aryan Mittal
Hua Hua
Programming Live with Larry
DeepCodes
TechError
Algorithms for Big Bucks
Solve more problems to master this pattern