Check If It Is a Good Array

Given an array nums of positive integers. Your task is to select some subset of nums, multiply each selected element by an integer, and add all these numbers. The array is said to be good if you can obtain a sum of 1 from the array by any possible subset and multiplicand.

Return true if the array is good, otherwise return false.

Example 1
Inputnums = [12,5,7,23]
Outputtrue
Pick numbers 5 and 7: 5 * 3 + 7 * (-2) = 1.
Example 2
Inputnums = [29,6,10]
Outputtrue
Pick numbers 29, 6, and 10: 29 * 1 + 6 * (-3) + 10 * (-1) = 1.

Constraints

  • 1 <= nums.length <= 10^5
  • 1 <= nums[i] <= 10^9

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate