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...

TCS Software Developer interview questions & answers

A Software Developer was asked 1w agoQ. What is Python?
A Software Developer was asked 1w agoQ. What is SQL?
A Software Developer was asked 4w agoQ. What is the process flow for converting an infix expression to a postfix express...read more

Popular interview questions of Software Developer

A Software Developer was asked 4w agoQ1. What is the process flow for converting an infix expression to a postfix express...read more
A Software Developer was asked 4w agoQ2. What is the process for synthesizing data to train a machine learning model with...read more
A Software Developer was asked 1mo agoQ3. Write code to reverse a string.

Top HR questions asked in TCS Software Developer

A Software Developer was asked 5d agoQ1. Can you provide an explanation of your project?
A Software Developer was asked 2mo agoQ2. Why should we choose you?
A Software Developer was asked 2mo agoQ3. What are your hobbies?
TCS 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