![]() |
VOOZH | about |
A special two-digit number is a number such that when the sum of the digits of the number is added to the product of its digits, the result is equal to the original two-digit number.
Examples :
input : 59. output : 59 is a Special Two-Digit Number Explanation: Sum of digits = 5 + 9 = 14 Product of its digits = 5 x 9 = 45 Sum of the sum of digits and product of digits = 14 + 45 = 59 input: 29 output: 29 is a Special Two-digit Number Explanation: Sum of digits = 9 + 2 = 11 Product of digits = 9 * 2 = 18 Sum of the sum of digits and product of digits = 11 + 18 = 29
Approach:
Extract the first and last digit of the number and add and multiply the digits separately. Then, add the sum and product of the digits of the two-digit number and compare it to the original number. If they are same, then it is a Special Two-Digit Number, else it is not.
Below is the implementation of above approach:
59 is a Special Two-Digit Number
Time Complexity: O(1), As we are performing constant time operations.
Auxiliary Space: O(1), As constant extra space is used.