Help me in solving LEQEX problem ,one of the super question , so help me to find the answer

My issue

what type of algorithm should i follow
for the second and third case i can guess it but the first case is not following that formate if it follows it should have 5 as its height but it is 3 instead
so please help me to solve this problem thankyou

My code

# cook your dish here

Problem Link: LEQEX Problem - CodeChef