Painter's Partition problem

I’m getting WA for 0 2 4 test cases. Please help
code link: https://ide.codingblocks.com/s/232836

@SWIFTY don’t sort the boards array as order of elements affects answer.

refer this for more of your mistakes