I am trying to solve this Hackerank problem and some of my test cases are failing stating that the final answer is wrong. After going over a previous S.O question for the same p