Interview Query

Ugly Powers

Start Timer

0:00:00

Upvote
3
Downvote
Save question
Mark as completed
View comments (2)
Next question

A Hamming Number (also called an ugly number) is any positive integer that has its set of prime factors as a subset of the prime numbers 2, 3, and 5. On the other hand, a prime power is produced using any integer kk raised to a prime pp, and is represented as pkp^k.

As such, we can create a theoretical term, an “ugly power,” which is any ugly number multiplied by any arbitrary positive integer kk. We can represent this by having any ugly number hh, and an ugly power be hkh^k.

Write a function ugly_powers(s: set) -> bool which takes a set ss and returns a boolean value determining whether or not all the elements of set ss are all ugly powers.

Note: Can you write a solution that’s approximately O(n  log(n))O(n\;log(n))?

Example:

ugly_powers({1, 2, 5, 10}) -> True
.
.
.
.
.


Comments

Loading comments