Watch tutorials and explanations by expert teachers that walk through solving this problem.
R Sai Siddhu
Leet's Code
CodeVia
Leetcode Solutions
Luc Taylor
Saone.777
LetsCode
Solve more problems to master this pattern