#3480

Maximize Subarrays After Removing One Conflicting Pair

expert · 1105 · lc hard +32 · 64.7% accepted · 305 likes · top 68%

Description

Array nums contains integers from 1 to n in order. You are also given conflictingPairs, where each pair [a, b] marks two values that must not both appear in a subarray.

Delete exactly one pair from conflictingPairs, then count the non-empty subarrays of nums that violate none of the remaining pairs.

Return the maximum count achievable by choosing which pair to remove optimally.

Code

1
2
3