Binary tree check property and delete the invalid nodes

Please explain the below question approach along with the code