Watch tutorials and explanations by expert teachers that walk through solving this problem.
Reducible
NeetCode
Tushar Roy - Coding Made Simple
NeetCodeIO
CodeHelp - by Babbar
Techdose
Solve more problems to master this pattern