Getting Segmentation fault

https://ide.codingblocks.com/s/295949 Here is the Code

You code is giving wrong output for the given sample test case.
Refer this https://ide.codingblocks.com/s/280601

You can verify your approach from this video