983. Number Of Equal Numbers Block

An array of numbers, nums, with a 0-index is shown to you. For nums, the following property is true:

  • Every instance of a value is next to it. Stated differently, for each index k that i < k < j, nums[k] == nums[i] if there are two indices i < j such that nums[i] == nums[j].

You are given an instance of the class BigArray, which has the following functions, because nums is a very huge array:

  • int at(long long index): Returns the value of nums[i].
  • void size(): Returns nums.length.

The array should be divided into maximum blocks with equal values in each block. Give back the quantity of these blocks.

Example 1:

Input : nums = [1, 1, 5, 5, 5, 2, 4, 4]

Output : 4

Explanation :

Block number 1: [1, 1, 5, 5, 5, 2, 4, 4]

Block number 2: [1, 1, 5, 5, 5, 2, 4, 4]

Block number 3: [1, 1, 5, 5, 5, 2, 4, 4]

Block number 4: [1, 1, 5, 5, 5, 2, 4, 4]

So the answer would be 4.

Example 2:

Input : nums = [1, 1, 1, 1]

Output : 1

Explanation :

Block number 1: [1, 1, 1, 1]

So the answer would be 1.

Now Your Turn!

Pick the correct output for the given input

Input : nums = [1, 2, 3, 4, 4, 5, 6, 7]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= nums.length <= 1015
  • 1 <= nums[i] <= 109
  • The input is generated such that all equal values are adjacent.
  • The sum of the elements of nums is at most 1015.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
int countBlocks(BigArray* nums) {
//your code goes here
}
};
Test Case

Input:

Nums