The main problem of the question is TLE i.e. time limit exceeded error, so to overcome the problem we design a more reliable and fast algorithm, which is explained in the video.
Link to the question:
https://www.hackerrank.com/challenges...
Please tell me in the comment section if you want me to solve any other problems (any platform). I'll be more than happy to solve them!