1250. Check If It Is a Good Array LeetCode Solution
In this guide, you will get 1250. Check If It Is a Good Array LeetCode Solution with the best time and space complexity. The solution to Check If It Is a Good Array problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Check If It Is a Good Array solution in C++
- Check If It Is a Good Array solution in Java
- Check If It Is a Good Array solution in Python
- Additional Resources

Problem Statement of 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 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:
Input: nums = [12,5,7,23]
Output: true
Explanation: Pick numbers 5 and 7.
5*3 + 7*(-2) = 1
Example 2:
Input: nums = [29,6,10]
Output: true
Explanation: Pick numbers 29, 6 and 10.
29*1 + 6*(-3) + 10*(-1) = 1
Example 3:
Input: nums = [3,6]
Output: false
Constraints:
1 <= nums.length <= 10^5
1 <= nums[i] <= 10^9
Complexity Analysis
- Time Complexity:
- Space Complexity:
1250. Check If It Is a Good Array LeetCode Solution in C++
class Solution {
public:
bool isGoodArray(vector<int>& nums) {
int g = nums[0];
for (const int num : nums)
g = __gcd(g, num);
return g == 1;
}
};
/* code provided by PROGIEZ */
1250. Check If It Is a Good Array LeetCode Solution in Java
N/A
// code provided by PROGIEZ
1250. Check If It Is a Good Array LeetCode Solution in Python
N/A
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.