Given an array of positive integers nums, a unique factor is an integer that satisfies both of the following conditions:
-
It appears in
nums
exactly once.
-
It divides the product of all elements in
nums
.
Return a list of all unique factors found in nums, sorted in ascending order. If no such element exists, return an empty list.
Function Signature
def unique_factor(nums: list[int]) -> list[int]:
Rules
-
A unique factor is a value taken from
nums
, and each one is reported once.
-
Return the values sorted in ascending order. An empty list is a valid answer.
Constraints
-
1 <= len(nums) <= 10^5
-
1 <= nums[i] <= 10^9
Examples
Input: nums = [2,3,2,5,7,7]
Output: [3,5]
The product of all elements is 2940. The values 3 and 5 each appear exactly once and both divide 2940. The values 2 and 7 appear twice, so they are excluded.
Input: nums = [4,4,4]
Output: []
The only value, 4, appears three times, so no element appears exactly once and the result is empty.
Input: nums = [1]
Output: [1]
The value 1 appears once, and it divides the product, which is 1.