Watch tutorials and explanations by expert teachers that walk through solving this problem.
NAGE FOREX
NeetCode
take U forward
Umar Ashraf
Tushar Roy - Coding Made Simple
Techdose
Solve more problems to master this pattern