3388. Count Beautiful Splits in an Array
3388. Count Beautiful Splits in an Array
Description
You are given an array nums
.
A split of an array nums
is beautiful if:
- The array
nums
is split into three subarrays:nums1
,nums2
, andnums3
, such thatnums
can be formed by concatenatingnums1
,nums2
, andnums3
in that order. - The subarray
nums1
is a prefix ofnums2
ORnums2
is a prefix ofnums3
.
Return the number of ways you can make this split.
Example 1:
1 | Input: nums = [1,1,2,1] |
Explanation:
The beautiful splits are:
- A split with
nums1 = [1]
,nums2 = [1,2]
,nums3 = [1]
. - A split with
nums1 = [1]
,nums2 = [1]
,nums3 = [2,1]
.
Example 2:
1 | Input: nums = [1,2,3,4] |
Explanation:
There are 0 beautiful splits.
Constraints:
1 <= nums.length <= 5000
0 <= nums[i] <= 50
Hints/Notes
- 2025/01/09
- z function
- 0x3Fâs solution(checked)
- Weekly Contest 428
Solution
Language: C++
1 | class Solution { |