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