Watch tutorials and explanations by expert teachers that walk through solving this problem.
NeetCode
Greg Hogg
NeetCodeIO
Aryan Mittal
Algorithms with Shayan
Solve more problems to master this pattern