java.lang.Object
g2501_2600.s2513_minimize_the_maximum_of_two_arrays.Solution

public class Solution extends Object
2513 - Minimize the Maximum of Two Arrays.<p>Medium</p> <p>We have two arrays <code>arr1</code> and <code>arr2</code> which are initially empty. You need to add positive integers to them such that they satisfy all the following conditions:</p> <ul> <li><code>arr1</code> contains <code>uniqueCnt1</code> <strong>distinct</strong> positive integers, each of which is <strong>not divisible</strong> by <code>divisor1</code>.</li> <li><code>arr2</code> contains <code>uniqueCnt2</code> <strong>distinct</strong> positive integers, each of which is <strong>not divisible</strong> by <code>divisor2</code>.</li> <li><strong>No</strong> integer is present in both <code>arr1</code> and <code>arr2</code>.</li> </ul> <p>Given <code>divisor1</code>, <code>divisor2</code>, <code>uniqueCnt1</code>, and <code>uniqueCnt2</code>, return <em>the <strong>minimum possible maximum</strong> integer that can be present in either array</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> divisor1 = 2, divisor2 = 7, uniqueCnt1 = 1, uniqueCnt2 = 3</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong></p> <p>We can distribute the first 4 natural numbers into arr1 and arr2.</p> <p>arr1 = [1] and arr2 = [2,3,4].</p> <p>We can see that both arrays satisfy all the conditions.</p> <p>Since the maximum value is 4, we return it.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> divisor1 = 3, divisor2 = 5, uniqueCnt1 = 2, uniqueCnt2 = 1</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong></p> <p>Here arr1 = [1,2], and arr2 = [3] satisfy all conditions.</p> <p>Since the maximum value is 3, we return it.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> divisor1 = 2, divisor2 = 4, uniqueCnt1 = 8, uniqueCnt2 = 2</p> <p><strong>Output:</strong> 15</p> <p><strong>Explanation:</strong></p> <p>Here, the final possible arrays can be arr1 = [1,3,5,7,9,11,13,15], and arr2 = [2,6].</p> <p>It can be shown that it is not possible to obtain a lower maximum satisfying all conditions.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= divisor1, divisor2 <= 10<sup>5</sup></code></li> <li><code>1 <= uniqueCnt1, uniqueCnt2 < 10<sup>9</sup></code></li> <li><code>2 <= uniqueCnt1 + uniqueCnt2 <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minimizeSet

      public int minimizeSet(int divisor1, int divisor2, int uniqueCnt1, int uniqueCnt2)