Watch tutorials and explanations by expert teachers that walk through solving this problem.
Greg Hogg
NeetCode
NeetCodeIO
Cracking FAANG
codi
ChunkCode01
Code Ninja
CodeFod
Solve more problems to master this pattern