Skip to content
LC-3012 Medium LeetCode

3012. Minimize Length of Array Using Operations

Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 35% Topics: Array, Math, Greedy, Number Theory
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(1)

# greedy
class Solution(object):
    def minimumArrayLength(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        mn = min(nums)
        return (nums.count(mn)+1)//2 if all(x%mn == 0 for x in nums) else 1

Solution from kamyu104/LeetCode-Solutions · MIT