Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3152 - Special Array II.

    Medium

    An array is considered special if every pair of its adjacent elements contains two numbers with different parity.

    You are given an array of integer nums and a 2D integer matrix queries, where for <code>queriesi = from<sub>i</sub>, to<sub>i</sub></code> your task is to check that subarray <code>numsfrom<sub>i</sub>..to<sub>i</sub></code> is special or not.

    Return an array of booleans answer such that answer[i] is true if <code>numsfrom<sub>i</sub>..to<sub>i</sub></code> is special.

    Example 1:

    Input: nums = 3,4,1,2,6, queries = [0,4]

    Output: false

    Explanation:

    The subarray is [3,4,1,2,6]. 2 and 6 are both even.

    Example 2:

    Input: nums = 4,3,1,6, queries = [0,2,2,3]

    Output: false,true

    Explanation:

    • The subarray is [4,3,1]. 3 and 1 are both odd. So the answer to this query is false.

    • The subarray is [1,6]. There is only one pair: (1,6) and it contains numbers with different parity. So the answer to this query is true.

    Constraints:

    • <code>1 <= nums.length <= 10<sup>5</sup></code>

    • <code>1 <= numsi<= 10<sup>5</sup></code>

    • <code>1 <= queries.length <= 10<sup>5</sup></code>

    • queries[i].length == 2

    • 0 &lt;= queries[i][0] &lt;= queries[i][1] &lt;= nums.length - 1

    • 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 BooleanArray isArraySpecial(IntArray nums, Array<IntArray> queries)
      • Methods inherited from class java.lang.Object

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