Painter's Problem Alternative approach

a different appproach I thought and implemented but there are some failed test cases in hackerblocks.

https://codeshare.io/G7KKqL

Approach is explained in the code with comments