Skip to content
Discussion options

You must be logged in to vote

We implement a straightforward solution that processes the input integer n by extracting all non-zero digits, constructing a new number from them, calculating their sum, and returning their product. Our approach handles the edge case where no non-zero digits exist by returning 0.

Approach

  • Digit Extraction: Convert the integer n to a string and split it into an array of individual digit characters
  • Filter Non-Zero Digits: Remove all digit characters equal to '0' using array filtering
  • Edge Case Handling: If no non-zero digits remain, return 0 immediately
  • Construct x: Join the filtered digit characters into a string and convert to integer
  • Calculate Sum: Sum the numeric values of all non-zero…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Jul 7, 2026
Maintainer Author

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Jul 7, 2026
Collaborator

@mah-shamim
Comment options

mah-shamim Jul 7, 2026
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants