Algorithms
Hard
2963
3212
Count the Number of Good Partitions
count-the-number-of-good-partitions
"""
You are given a 0-indexed array nums consisting of positive integers.
A partition of an array into one or more contiguous subarrays is called good if no two subarrays contain the same number.
Return the total number of good partitions of nums.
Since the answer may be large, return it modulo 109 + 7.

Example 1:

Input: nums = [1,2,3,4]
Output: 8
Explanation: The 8 possible good partitions are: ([1], [2], [3], [4]), ([1], [2], [3,4]), ([1], [2,3], [4]), ([1], [2,3,4]), ([1,2], [3], [4]), ([1,2], [3,4]), ([1,2,3], [4]), and ([1,2,3,4]).

Example 2:

Input: nums = [1,1,1,1]
Output: 1
Explanation: The only possible good partition is: ([1,1,1,1]).

Example 3:

Input: nums = [1,2,1,3]
Output: 2
Explanation: The 2 possible good partitions are: ([1,2,1], [3]) and ([1,2,1,3]).


Constraints:

1 <= nums.length <= 105
1 <= nums[i] <= 109
"""
class Solution:
    def numberOfGoodPartitions(self, nums: List[int]) -> int:
        
You are given a 0-indexed array nums consisting of positive integers.
A partition of an array into one or more contiguous subarrays is called good if no two subarrays contain the same number.
Return the total number of good partitions of nums.
Since the answer may be large, return it modulo 109 + 7.

Example 1:

Input: nums = [1,2,3,4]
Output: 8
Explanation: The 8 possible good partitions are: ([1], [2], [3], [4]), ([1], [2], [3,4]), ([1], [2,3], [4]), ([1], [2,3,4]), ([1,2], [3], [4]), ([1,2], [3,4]), ([1,2,3], [4]), and ([1,2,3,4]).

Example 2:

Input: nums = [1,1,1,1]
Output: 1
Explanation: The only possible good partition is: ([1,1,1,1]).

Example 3:

Input: nums = [1,2,1,3]
Output: 2
Explanation: The 2 possible good partitions are: ([1,2,1], [3]) and ([1,2,1,3]).


Constraints:

1 <= nums.length <= 105
1 <= nums[i] <= 109


Please complete the code below to solve above prblem:
```python
class Solution:
    def numberOfGoodPartitions(self, nums: List[int]) -> int:
        
```

my_solution = Solution()

test_input = { "nums": [1,2,3,4] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [1,1,1,1] }
assert my_solution.numberOfGoodPartitions(**test_input) == 1

test_input = { "nums": [1,2,1,3] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [1] }
assert my_solution.numberOfGoodPartitions(**test_input) == 1

test_input = { "nums": [100000] }
assert my_solution.numberOfGoodPartitions(**test_input) == 1

test_input = { "nums": [1000000000] }
assert my_solution.numberOfGoodPartitions(**test_input) == 1

test_input = { "nums": [1,1,1,3,2] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [1,1,1,9,7] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [1,1,5,9,2] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [1,4,1,7,5] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [1,5,1,5,6] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [1,5,1,10,8] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [1,6,8,1,5] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [1,6,9,4,10] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [1,7,1,6,8] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [1,9,1,1,7] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [2,1,6,7,5] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [2,3,2,6,9] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [2,3,2,8,8] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [2,3,9,2,6] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [2,4,2,7,4] }
assert my_solution.numberOfGoodPartitions(**test_input) == 1

test_input = { "nums": [2,4,7,1,2] }
assert my_solution.numberOfGoodPartitions(**test_input) == 1

test_input = { "nums": [2,5,1,2,2] }
assert my_solution.numberOfGoodPartitions(**test_input) == 1

test_input = { "nums": [2,5,1,4,9] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [2,5,6,4,2] }
assert my_solution.numberOfGoodPartitions(**test_input) == 1

test_input = { "nums": [2,6,1,9,5] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [2,7,8,9,3] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [2,9,1,2,4] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [2,10,4,2,3] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [3,3,3,9,9] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [3,3,8,1,6] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [3,3,10,4,2] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [3,4,5,1,7] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [3,7,6,4,9] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [3,8,10,7,6] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [3,10,10,10,4] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [4,1,2,3,10] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [4,1,7,9,4] }
assert my_solution.numberOfGoodPartitions(**test_input) == 1

test_input = { "nums": [4,8,4,8,6] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [5,1,1,9,3] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [5,2,8,10,4] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [5,3,6,6,6] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [5,3,8,8,2] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [5,4,5,9,9] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [5,4,10,2,4] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [5,5,7,3,1] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [5,5,8,4,1] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [5,9,1,9,2] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [5,10,1,1,6] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [6,1,7,9,10] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [6,3,5,1,10] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [6,3,9,9,3] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [6,6,5,5,8] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [6,7,3,3,8] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [6,8,6,5,7] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [6,9,10,5,8] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [6,10,2,6,10] }
assert my_solution.numberOfGoodPartitions(**test_input) == 1

test_input = { "nums": [6,10,5,4,3] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [7,1,2,3,5] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [7,1,9,2,1] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [7,2,1,2,6] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [7,5,1,10,10] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [7,5,7,4,6] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [7,5,8,4,6] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [7,9,4,8,7] }
assert my_solution.numberOfGoodPartitions(**test_input) == 1

test_input = { "nums": [7,9,8,8,4] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [8,2,2,5,6] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [8,3,2,1,9] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [8,3,4,9,7] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [8,3,6,5,1] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [8,3,8,3,4] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [8,3,8,3,10] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [8,4,4,5,8] }
assert my_solution.numberOfGoodPartitions(**test_input) == 1

test_input = { "nums": [8,4,8,10,9] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [8,5,5,3,9] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [8,7,4,2,1] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [8,7,6,10,1] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [8,9,7,3,6] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [8,10,5,9,9] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [9,1,2,2,3] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [9,1,4,3,7] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [9,1,7,8,9] }
assert my_solution.numberOfGoodPartitions(**test_input) == 1

test_input = { "nums": [9,2,7,5,10] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [9,3,6,5,5] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [9,4,7,1,1] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [9,5,5,8,3] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [9,7,2,7,10] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [9,7,8,3,2] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [9,8,2,5,5] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [9,8,2,10,7] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [9,8,3,7,6] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [9,8,6,6,8] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2

test_input = { "nums": [9,8,8,2,1] }
assert my_solution.numberOfGoodPartitions(**test_input) == 8

test_input = { "nums": [9,8,9,5,7] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [10,1,3,2,3] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [10,1,10,3,5] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [10,2,1,4,1] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [10,3,1,3,4] }
assert my_solution.numberOfGoodPartitions(**test_input) == 4

test_input = { "nums": [10,5,6,2,8] }
assert my_solution.numberOfGoodPartitions(**test_input) == 16

test_input = { "nums": [10,6,5,10,2] }
assert my_solution.numberOfGoodPartitions(**test_input) == 2