Buy and sell stock best time

pls explain this sir, i am not getting its solution logic.