2936. Number of Equal Numbers Blocks
You are given a 0-indexed array of integers,
nums
. The following property holds fornums
:
- All occurrences of a value are adjacent. In other words, if there are two indices
i < j
such thatnums[i] == nums[j]
, then for every indexk
thati < k < j
,nums[k] == nums[i]
.Since
nums
is a very large array, you are given an instance of the classBigArray
which has the following functions:
int at(long long index)
: Returns the value ofnums[i]
.void size()
: Returnsnums.length
.Let’s partition the array into maximal blocks such that each block contains equal values. Return the number of these blocks.
Note that if you want to test your solution using a custom test, behavior for tests with
nums.length > 10
is undefined.
1 | /** |