Algorithms
Medium
2799
2856
Count Complete Subarrays in an Array
count-complete-subarrays-in-an-array
"""
You are given an array nums consisting of positive integers.

We call a subarray of an array complete if the following condition is satisfied:

 * The number of distinct elements in the subarray is equal to the number of distinct elements in the whole array.

Return the number of complete subarrays.

A subarray is a contiguous non-empty part of an array.

Example 1:

Input: nums = [1,3,1,2,2]
Output: 4
Explanation: The complete subarrays are the following: [1,3,1,2], [1,3,1,2,2], [3,1,2] and [3,1,2,2].

Example 2:

Input: nums = [5,5,5,5]
Output: 10
Explanation: The array consists only of the integer 5, so any subarray is complete. The number of subarrays that we can choose is 10.


Constraints:

 * 1 <= nums.length <= 1000
 * 1 <= nums[i] <= 2000
"""
class Solution:
    def countCompleteSubarrays(self, nums: List[int]) -> int:
        
You are given an array nums consisting of positive integers.

We call a subarray of an array complete if the following condition is satisfied:

 * The number of distinct elements in the subarray is equal to the number of distinct elements in the whole array.

Return the number of complete subarrays.

A subarray is a contiguous non-empty part of an array.

Example 1:

Input: nums = [1,3,1,2,2]
Output: 4
Explanation: The complete subarrays are the following: [1,3,1,2], [1,3,1,2,2], [3,1,2] and [3,1,2,2].

Example 2:

Input: nums = [5,5,5,5]
Output: 10
Explanation: The array consists only of the integer 5, so any subarray is complete. The number of subarrays that we can choose is 10.


Constraints:

 * 1 <= nums.length <= 1000
 * 1 <= nums[i] <= 2000


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

my_solution = Solution()

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

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

test_input = { "nums": [459,459,962,1579,1435,756,1872,1597] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

test_input = { "nums": [1786,1786,1786,114] }
assert my_solution.countCompleteSubarrays(**test_input) == 3

test_input = { "nums": [1632,1632,528,359,1671,1632,511,1087,424,1684] }
assert my_solution.countCompleteSubarrays(**test_input) == 3

test_input = { "nums": [1430,12,1430,1075,1722] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

test_input = { "nums": [1917,1917,608,608,1313,751,558,1561,608] }
assert my_solution.countCompleteSubarrays(**test_input) == 4

test_input = { "nums": [254,1690,1690,1068,1779] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

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

test_input = { "nums": [1677,1677,1352,1219,1666,1677,1892,1892,319] }
assert my_solution.countCompleteSubarrays(**test_input) == 3

test_input = { "nums": [1386,1997,1997,574,574,1360,989] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [50,48,1118,540,1248,1984,1698,41,1984,186] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [273,524,40,1323,1323] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

test_input = { "nums": [246,376,828,191,1942,210] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [463,1497,1676,127,1379,17,1075,190] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

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

test_input = { "nums": [1110,804,1110,839,728,839] }
assert my_solution.countCompleteSubarrays(**test_input) == 4

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

test_input = { "nums": [665,867,954,1411,728,1006,372,1411] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

test_input = { "nums": [1213,1203,1277,369,1277] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

test_input = { "nums": [1898,370,822,1659,1360,128,370,360,261,1898] }
assert my_solution.countCompleteSubarrays(**test_input) == 4

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

test_input = { "nums": [474,315,155,155,1986] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [1389,1817,401,1067,1356,1997] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [1586,1332,1055,1586,1586,1861,892,1445] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

test_input = { "nums": [1601,1601] }
assert my_solution.countCompleteSubarrays(**test_input) == 3

test_input = { "nums": [1417,1417,1160,387,928,1572,1832] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

test_input = { "nums": [1497,1237,1237,946,682,331,742] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [377,377] }
assert my_solution.countCompleteSubarrays(**test_input) == 3

test_input = { "nums": [356,356,356,356,356,315] }
assert my_solution.countCompleteSubarrays(**test_input) == 5

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

test_input = { "nums": [211,211,731,226] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

test_input = { "nums": [1253,188,188,5,1393,1696,1062] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [90,1297,482,482,90,1836,1045,1497,482] }
assert my_solution.countCompleteSubarrays(**test_input) == 4

test_input = { "nums": [1857,273,609,609,1803,1491,223,609,1857,1052] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

test_input = { "nums": [617,1014,679,934,955] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [577,577] }
assert my_solution.countCompleteSubarrays(**test_input) == 3

test_input = { "nums": [1793,997,1082,1411,997,546,224,336,307,336] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

test_input = { "nums": [1150,1150] }
assert my_solution.countCompleteSubarrays(**test_input) == 3

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

test_input = { "nums": [1454,1789,1454] }
assert my_solution.countCompleteSubarrays(**test_input) == 3

test_input = { "nums": [1657,1090,1682,1376,547,547,407,755,1124,1376] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

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

test_input = { "nums": [1673,1584,1584,1055,1971,1122,1086,1692,75] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

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

test_input = { "nums": [1641,448,1641,1437,448,1406,1437] }
assert my_solution.countCompleteSubarrays(**test_input) == 6

test_input = { "nums": [1440,704,1440,1440,749] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

test_input = { "nums": [832,832] }
assert my_solution.countCompleteSubarrays(**test_input) == 3

test_input = { "nums": [1635,1759,1759,1976,700] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [1577,1674,1745,156,596,1973,1390,156,1497,415] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

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

test_input = { "nums": [1613,881,1660,1270,1783,881,773,1783,1229,111] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

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

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

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

test_input = { "nums": [999,701,389,999,409,488,993,999,517,1860] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

test_input = { "nums": [236,596,1263,1563,860,596,1184,575] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

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

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

test_input = { "nums": [1293,564,614,694,1386,564] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

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

test_input = { "nums": [1563,558,1778,1404,1973] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [1508,1508,649] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

test_input = { "nums": [1077,445,1947,445,789,789,789,956,1988,189] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [1984,526,30,1205,1691,1984,1241,280,280,1984] }
assert my_solution.countCompleteSubarrays(**test_input) == 6

test_input = { "nums": [1802,1876,1143,1802,1012,1876,1802,1821] }
assert my_solution.countCompleteSubarrays(**test_input) == 3

test_input = { "nums": [1338,901,613,575,613] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

test_input = { "nums": [406,406,242,242,770,1063,1436,1063,1063] }
assert my_solution.countCompleteSubarrays(**test_input) == 6

test_input = { "nums": [1235,1235] }
assert my_solution.countCompleteSubarrays(**test_input) == 3

test_input = { "nums": [1337,1088,1088,892,1209,1269] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [1941,1941] }
assert my_solution.countCompleteSubarrays(**test_input) == 3

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

test_input = { "nums": [1891,1891,1748,1748,923,1748,923,763,1062,1748] }
assert my_solution.countCompleteSubarrays(**test_input) == 4

test_input = { "nums": [1111,503,1980] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [213,1666,469,1675] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [769,1774,1654,928,1204] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [294,294,294,294,1351,294,1351,62,585] }
assert my_solution.countCompleteSubarrays(**test_input) == 6

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

test_input = { "nums": [21,1549,21,1549,1998,1219,1549,1021] }
assert my_solution.countCompleteSubarrays(**test_input) == 3

test_input = { "nums": [1124,1124,556,1322,556] }
assert my_solution.countCompleteSubarrays(**test_input) == 4

test_input = { "nums": [908,908,863,1977,908,8,427,1322] }
assert my_solution.countCompleteSubarrays(**test_input) == 3

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

test_input = { "nums": [517,1497,334,334,996,1497,1394,534] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [564,750,750,750,1965,1965,1402] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [403,1080,365,1962,1589,1740,1335,1335,1589] }
assert my_solution.countCompleteSubarrays(**test_input) == 3

test_input = { "nums": [1712,1621,1295,522,1734,522,1371,1935,684] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [270,1443,807,1704,1487] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [1880,1880,1880,604,1634,1412,1880,67,1759,1488] }
assert my_solution.countCompleteSubarrays(**test_input) == 4

test_input = { "nums": [540,1799,1784,1799,972,1786,1578,1480,178,532] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [1235,471,367] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [1887,1373,190,1764,1764,959,959,1373,17] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [1313,910,1172,1541,1758,140,1380,492,240,1664] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [381,1304,381,758,1304,381,758] }
assert my_solution.countCompleteSubarrays(**test_input) == 14

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

test_input = { "nums": [1555,223,379,223,379,1982] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [1268,1268,1268,1268] }
assert my_solution.countCompleteSubarrays(**test_input) == 10

test_input = { "nums": [1051,266,266,94,761,1051,255] }
assert my_solution.countCompleteSubarrays(**test_input) == 3

test_input = { "nums": [420,945,3,172] }
assert my_solution.countCompleteSubarrays(**test_input) == 1

test_input = { "nums": [1045,1120,1045,511,1045,1777,1224,336,560,153] }
assert my_solution.countCompleteSubarrays(**test_input) == 2

test_input = { "nums": [627,592,592,1416,370,229,526,633] }
assert my_solution.countCompleteSubarrays(**test_input) == 1