Almost solved Ones and Twos problem from Hackerrank contest - March 20/20