Code is working fine in sublime text but in the online editor provided by coding blocks. You can refer code below
@slow_motion, Try running on CB IDE with a test case(ie valid input).