Code not working

I would suggest you to go through the online video lecture on the problem and then implement your solution accordingly…