Watch tutorials and explanations by expert teachers that walk through solving this problem.
Road To FAANG
Let's Practice Together
Prakhar Agrawal
StatLearn Tech
Consistent Code
Yersham
Sleepy Cracker
Codeforces Round #817
Solve more problems to master this pattern