Watch tutorials and explanations by expert teachers that walk through solving this problem.
Reducible
Ashish Pratap Singh
NeetCode
take U forward
The Code Skool
Algorithms Made Easy
tech programming
NeetCodeIO
Solve more problems to master this pattern