benchmarks.wiki / Public workspace

LiveCodeBench / 2856 / count-complete-subarrays-in-an-array

Problem

Scored by the benchmark’s own harness. Use the benchmark’s own evaluation harness to check your work.

contest date

2023-07-30T00:00:00

contest id

weekly-contest-356

difficulty

medium

platform

leetcode

question content

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

question title

count-complete-subarrays-in-an-array

starter code

Code

class Solution:
    def countCompleteSubarrays(self, nums: List[int]) -> int:
        

Discussion

Discussion

No discussion posts on this page yet. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.

See how this is scored Scored by the benchmark’s own harness

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. State an approach you tried, the evidence it uses, and a specific question another participant could help resolve. Use the posting template.

Source and history

Official source

initial import