Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3468 - Find the Number of Copy Arrays.

    Medium

    You are given an array original of length n and a 2D array bounds of length n x 2, where <code>boundsi = u<sub>i</sub>, v<sub>i</sub></code>.

    You need to find the number of possible arrays copy of length n such that:

    • (copy[i] - copy[i - 1]) == (original[i] - original[i - 1]) for 1 &lt;= i &lt;= n - 1.

    • <code>u<sub>i</sub><= copyi<= v<sub>i</sub></code> for 0 &lt;= i &lt;= n - 1.

    Return the number of such arrays.

    Example 1:

    Input: original = 1,2,3,4, bounds = [1,2,2,3,3,4,4,5]

    Output: 2

    Explanation:

    The possible arrays are:

    • [1, 2, 3, 4]

    • [2, 3, 4, 5]

    Example 2:

    Input: original = 1,2,3,4, bounds = [1,10,2,9,3,8,4,7]

    Output: 4

    Explanation:

    The possible arrays are:

    • [1, 2, 3, 4]

    • [2, 3, 4, 5]

    • [3, 4, 5, 6]

    • [4, 5, 6, 7]

    Example 3:

    Input: original = 1,2,1,2, bounds = [1,1,2,3,3,3,2,3]

    Output: 0

    Explanation:

    No array is possible.

    Constraints:

    • <code>2 <= n == original.length <= 10<sup>5</sup></code>

    • <code>1 <= originali<= 10<sup>9</sup></code>

    • bounds.length == n

    • bounds[i].length == 2

    • <code>1 <= bounds0<= bounds1<= 10<sup>9</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer countArrays(IntArray original, Array<IntArray> bounds)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait