K-th Ugly Ninja Problem Statement

Ninja is looking to hire 'ugly ninjas' whose numbers have all prime factors from a given list. Your task is to help him find the K-th ugly ninja.

You will be given an array PRIME_ARR containing prime integers and an integer K.

Example:

Input:
PRIME_ARR = [2, 7, 13, 19], K = 12
Output:
32
Explanation:

First 12 ugly numbers are { 1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32 } derived using the primes in PRIME_ARR.

Constraints:

  • 1 <= T <= 50
  • 1 <= N <= 100
  • 1 <= K <= 10^3
  • 1 <= PRIME_ARR[i] <= 1000
  • Time Limit: 1sec
AnswerBot
4mo

Find the K-th ugly ninja number using prime factors from a given list.

  • Generate ugly numbers using prime factors from PRIME_ARR

  • Keep track of the K-th ugly number

  • Return the K-th ugly number

Help your peers!
Select
Add answer anonymously...

MathWorks Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Interest in Matlab
A Software Developer Intern was asked Q. Car Pooling Capacity Problem You are a cab driver with a car that initially has ...read more
A Software Developer Intern was asked Q. Distance To Nearest 1 in a Binary Matrix Problem Given a binary matrix MAT conta...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Interest in Matlab
A Software Developer Intern was asked Q2. Car Pooling Capacity Problem You are a cab driver with a car that initially has ...read more
A Software Developer Intern was asked Q3. Distance To Nearest 1 in a Binary Matrix Problem Given a binary matrix MAT conta...read more
MathWorks Software Developer Intern 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