After some trial and error i was able to get the expected behavior of codeblock
Answer : you have to write codeblock one after other without any text in between. (refer image below)
markdown img on leetcode