Skip to content

Instantly share code, notes, and snippets.

@tatsuyax25
Created September 8, 2025 19:53
Show Gist options
  • Select an option

  • Save tatsuyax25/650b9a768dd9c6de1548ea42f888428f to your computer and use it in GitHub Desktop.

Select an option

Save tatsuyax25/650b9a768dd9c6de1548ea42f888428f to your computer and use it in GitHub Desktop.
No-Zero integer is a positive integer that does not contain any 0 in its decimal representation. Given an integer n, return a list of two integers [a, b] where: a and b are No-Zero integers. a + b = n The test cases are generated so that there is a
/**
* Helper function to check if a number is a No-Zero integer
* A No-Zero integer has no '0' digit in its decimal representation
*/
function isNoZero(num) {
return !num.toString().includes('0');
};
/**
* Main function to find two No-Zero integers that sum to n
* @param {number} n - The target sum
* @returns {[number, number]} - A valid pair [a, b] such that a + b = n and both are No-Zero
*/
var getNoZeroIntegers = function(n) {
// Try all values of a from 1 to n - 1
for (let a = 1; a < n; a++) {
let b = n - a; // Compute b so that a + b = n
// Check if both a and b are No-Zero integers
if (isNoZero(a) && isNoZero(b)) {
return [a, b]; // Return the first valid pair found
}
}
// This line should never be reached because the problem guarantees a solution
return [];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment