Watch tutorials and explanations by expert teachers that walk through solving this problem.
CodeHelp - by Babbar
NeetCode
Nick White
NeetCodeIO
Algorithms Illustrator
Solve more problems to master this pattern