GSUB not passing Subtask 2 Last Task

My Solution

My solution is coming partially correct. I am not able to get a test case which is not passing the task. Would appreciate help.

Thanks.