Watch tutorials and explanations by expert teachers that walk through solving this problem.
NeetCode
Happy Coding
Ben Dickey
Java Coding Insight Interview Preparation
SCALive
Code Circle
Hanu
Solve more problems to master this pattern