Painter's problem

please check my code. I’m not getting the correct output.