Help me in solving CUTBOARD problem

My issue

can anyone explain the approach?

My code

# cook your dish here

Problem Link: Cut the Board Practice Coding Problem