Painter's Partition

Can only pass two test cases
here’s the code: https://ide.codingblocks.com/s/298911