Hacker Rank : Solve me first - Refactor for unit testability. Added unit test.