Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
The problem can be solved by considering different cases.
Let the minimum value in <code>nums</code> be <code>x</code>; we can consider the following cases:
If <code>x</code> occurs once: The minimum length of <code>nums</code> achievable in this case is <code>1</code>, since every other value, <code>y</code>, can be paired with <code>x</code>, resulting in deleting <code>x</code> and <code>y</code>, and inserting <code>x % y == x</code>, since <code>x < y</code>. So, only <code>x</code> remains after the operations.
If there is a value <code>y</code> in <code>nums</code> such that <code>y % x</code> is not equal to <code>0</code>: The minimum achievable length in this case is <code>1</code> as well, because inserting <code>y % x</code> creates a new minimum, since <code>y % x < x</code>, returning to the first case.
If neither of the previous cases holds, and <code>x</code> occurs <code>cnt</code> times: The minimum length of <code>nums</code> achievable in this case is <code>ceil(cnt / 2)</code>.