java.lang.Object
g1301_1400.s1354_construct_target_array_with_multiple_sums.Solution

public class Solution extends Object
1354 - Construct Target Array With Multiple Sums.<p>Hard</p> <p>You are given an array <code>target</code> of n integers. From a starting array <code>arr</code> consisting of <code>n</code> 1&rsquo;s, you may perform the following procedure :</p> <ul> <li>let <code>x</code> be the sum of all elements currently in your array.</li> <li>choose index <code>i</code>, such that <code>0 <= i < n</code> and set the value of <code>arr</code> at index <code>i</code> to <code>x</code>.</li> <li>You may repeat this procedure as many times as needed.</li> </ul> <p>Return <code>true</code> <em>if it is possible to construct the</em> <code>target</code> <em>array from</em> <code>arr</code><em>, otherwise, return</em> <code>false</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> target = [9,3,5]</p> <p><strong>Output:</strong> true</p> <p><strong>Explanation:</strong> Start with arr = [1, 1, 1]</p> <p>[1, 1, 1], sum = 3 choose index 1</p> <p>[1, 3, 1], sum = 5 choose index 2</p> <p>[1, 3, 5], sum = 9 choose index 0</p> <p>[9, 3, 5] Done</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> target = [1,1,1,2]</p> <p><strong>Output:</strong> false</p> <p><strong>Explanation:</strong> Impossible to create target array from [1,1,1,1].</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> target = [8,5]</p> <p><strong>Output:</strong> true</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == target.length</code></li> <li><code>1 <= n <= 5 * 10<sup>4</sup></code></li> <li><code>1 <= target[i] <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • isPossible

      public boolean isPossible(int[] target)