This solution does not use any extra data structure. Only a few variables are needed: x stores the integer formed by concatenating all non-zero digits. sum stores the sum of the non-zero digits.