https://ide.codingblocks.com/s/279447 pls check only 1 testcase is not running
You are close. You can have a look at this code for reference.