Smallest Number with Given Digit Product

Given a positive integer 'N', find and return the smallest number 'M', such that the product of all the digits in 'M' is equal to 'N'. If such an 'M' is not possible or if 'M' cannot fit in a 32-bit signed integer, return 0.

Example:

Input:
N = 90
Output:
259
Explanation:

For 'N' = 90, the possible values for 'M' include 259 (2*5*9 = 90), 3352 (3*3*5*2 = 90), 2335 (2*3*3*5 = 90), and 952 (9*5*2 = 90), among others. The smallest possible 'M' is 259, hence, the answer is 259.

Constraints:

  • 1 <= T <= 1000
  • 1 <= N <= 109
  • Time limit: 1 sec
AnswerBot
4mo

Find the smallest number with given digit product equal to a positive integer N.

  • Iterate from 2 to 9 and find the smallest digit that divides N, then add it to the result.

  • Repeat the process until N is ...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Interview Questions Asked at TCS

Q. What is Python?
Q. What is SQL?
Q. What is the process flow for converting an infix expression to a postfix express...read more
Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits