Painter Partition problem

Only 50% of the test cases are passing. I followed the methodology shown in the tutorial video. Please see into why I am getting some test cases as wrong. here is my code: https://ide.codingblocks.com/s/243026

check function is wrong


refer this to crrect check function

thanks, I actually interpreted the question in a slightly different way.