Is there anything redundant in this code? can it be made better? is it the right approach?

@sirraghavgupta If it is passing all the test cases then Ok. Else you can refer this solution:
https://ide.codingblocks.com/s/117015