` ````
```

Auto Saved.

Loading Question ...

- Total Accepted:
**33179** - Total Submissions:
**89065** - Difficulty:
**Medium** - Contributors:
**Admin**

Write a program to find the n^{th} super ugly number.

Super ugly numbers are positive numbers whose all prime factors are in the given prime list
`primes`

of size `k`

. For example, ```
[1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32]
```

is the sequence of the first 12 super ugly numbers given `primes`

= `[2, 7, 13, 19]`

of size 4.

**Note:**

(1) `1`

is a super ugly number for any given `primes`

.

(2) The given numbers in `primes`

are in ascending order.

(3) 0 < `k`

≤ 100, 0 < `n`

≤ 10^{6}, 0 < `primes[i]`

< 1000.

(4) The n^{th} super ugly number is guaranteed to fit in a 32-bit signed integer.

**Credits:**

Special thanks to @dietpepsi for adding this problem and creating all test cases.

Subscribe to see which companies asked this question.

Show Similar Problems

(M) Ugly Number II
Have you met this question in a real interview?

Yes

No

When did you meet this question?

last week

last month

last 3 month

last 6 month

more than 6 months

other

Which company asked you this question?

Adobe

Aetion

Affirm

Airbnb

Alation

Alibaba

Amazon

AppDynamics

Apple

Arista

Baidu

Bank of America

BlackRock

Blend Labs

Blizzard

Bloomberg

Booking

Box

Bungie

Capital One

CareerBuilder

Cisco

Citadel

Coinbase

Concur

Conviva

Coupang

Coursera

CreditEase

CVTE

Dell

Deutsche Bank

DoorDash

Dropbox

Duolingo

EasyNet

eBay

Electronic Arts

EMC

Epic Systems

Equinix

Evernote

Expedia

Facebook

FactSet

Fitbit

Flipkart

Fortinet

FourSquare

FreeWheel

GoDaddy

Goldman Sachs

Google

GrabTaxi

Groupon

HBO

Hedvig

HomeAway

HTC

Huawei

Hulu

IBG

IBM

Indeed

InnovatureLabs

Intel

IXL

Jane Street

JPMorgan

Jump Trading

Lending Club

LinkedIn

LiveRamp

Loovee

Marvel

Matlab

McKesson

Microsoft

Morgan Stanley

NetEase

Nintendo

Nutanix

Nvidia

Oracle

Orbitz

Palantir

Paypal

Pinterest

Pocket Gems

Point72

Qualcomm

Qualtrics

Qumulo

Quora

Rackspace

Redfin

Rubrik

Salesforce

Samsung

SAP

ServiceNow

Sina

Snapchat

SoftwareOne

Sony

SoundHound

Square

Sumologic

SurveyMonkey

Symantec

Tableau

Tencent

Tesorio

TinyCo

Tradeshift

TripAdvisor

Twilio

Twitter

Two Sigma

Uber

Veritas

Visa

VMware

Walmart

Wealthfront

Whitepages

Works Applications

Yahoo

Yandex

Yelp

Zappos

Zenefits

Zillow

Zynga

Code editor is not supported in mobile browser.