Can we apply my approach

i use height function to approach this question and getting wrong ans. how can i correct my approach please tell

Please explain your approach or comment out your code