Is_balanced Modified verion of this function for leetcode

Leet code is_balanced with modification
Could someone help me with modified version of is_balanced function with strict rules as is the leet code question.