Skip to content

Practice Minimize Length of Array Using Operations

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3012
LeetCode Problem

Minimize Length of Array Using Operations

Problem Statement

Given a positive-integer array nums, you may repeatedly choose distinct indices i and j whose values are both positive. Append nums[i] % nums[j] and remove the two chosen elements. A zero produced by an operation cannot be selected as either operand later. Return the minimum possible length after any number of operations, including none.

Source: Minimize Length of Array Using Operations on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [1,4,3,1]
Output
1

# Example 2

Input
nums = [5,5,5,10,5]
Output
2

# Example 3

Input
nums = [2,3,4]
Output
1

Constraints

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

Related LeetCode Problems

Practice more problems similar to Minimize Length of Array Using Operations.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.