DSA Learning Series - Stupid Machine

Can anyone explain me the approach / methodology of the solution for the question Stupid Machine of DSA Learning Series mentioned below . I wnna know how did he come up to this solution. So that i can also try to think like that which will help me in my DSA learning journey. Since i have been struggling to come up with an optimal solution.Thanks.

Solution of Stupid Machine

The Editorial describes the approach:

1 Like