GETTING TLE FOR SOME CASES

MY CODE =>https://ide.codingblocks.com/s/265468
I am getting a tle for this question possibly due to the constraint so can u guide me with some other concept using which i can solve this

@gagangoyal674 first using DFS find all the position which are connected and size of each connected part and give them id.
After that check if a position is 0 and it’s four sides have different I’d add the size of those I’d and store the max and output it