Tap here to switch tabs
Problem
Submissions

Problem: Check if There is a Valid Partition For The Array

med
30 min
Try to solve the Check if There is a Valid Partition For The Array problem.

Statement

Given an integer array nums, determine if there exists at least one valid partition of the array.

A partition is considered valid if the entire array can be divided into one or more contiguous subarrays such that every subarray satisfies at least one of the following conditions:

  1. The subarray consists of exactly 22 equal elements (for example, [x, x]).

  2. The subarray consists of exactly 33 equal elements (for example, [x, x, x]).

  3. The subarray consists of exactly 33 consecutive increasing elements, where the difference between adjacent elements is equal to 11 (for example, [x, x + 1, x + 2]).

Return true if nums has at least one valid partition, or false otherwise.

Constraints:

  • 2≤2 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Check if There is a Valid Partition For The Array

med
30 min
Try to solve the Check if There is a Valid Partition For The Array problem.

Statement

Given an integer array nums, determine if there exists at least one valid partition of the array.

A partition is considered valid if the entire array can be divided into one or more contiguous subarrays such that every subarray satisfies at least one of the following conditions:

  1. The subarray consists of exactly 22 equal elements (for example, [x, x]).

  2. The subarray consists of exactly 33 equal elements (for example, [x, x, x]).

  3. The subarray consists of exactly 33 consecutive increasing elements, where the difference between adjacent elements is equal to 11 (for example, [x, x + 1, x + 2]).

Return true if nums has at least one valid partition, or false otherwise.

Constraints:

  • 2≤2 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤106\leq 10^6