Given an array **arr[]**, consisting of **N** integers, the task is to check whether the entire array is only made up of subarrays such that each subarray consists of consecutive repetitions of a single element and every distinct element in the array is part of such subarray.**Examples:**

Input:N = 10, arr[] = {1, 1, 1, 1, 2, 2, 3, 3, 3, 3}Output:YesExplanation:

The given array consists of 3 distinct elements {1, 2, 3} and subarrays {1, 1, 1, 1}, {2, 2}, {3, 3, 3, 3}.

Therefore, the given array satisfies the conditions.Input:N = 10, arr[] = {1, 1, 1, 2, 2, 2, 2, 1, 3, 3}Output:NoExplanation:

The given array consists of 3 distinct elements {1, 2, 3} and subarrays {1, 1, 1}, {2, 2, 2, 2}, {1}, {3, 3}.

Since the subarray {1} does not contain any repetition, the given array does not satisfy the conditions.

**Approach:**

Follow the steps below to solve the problem:

- Initialize a variable
**curr = 0**to store the size of every subarray of a single repeating element is encountered. - If any such index is found where
**arr[i] ≠ arr[i – 1]**, check if**curr**is greater than**1**or not. If so, reset**curr**to**0**and continue. Otherwise, print “**No”**as a subarray exists of a single element without repetition. - Otherwise, increase
**curr**. - After traversing the array, check if
**curr**is greater than**1**or not. If**curr**is equal to**1**, this ensures that the last element is different from the second last element. Therefore, print “**No”**. - Otherwise, print “
**Yes”**.

Below is the implementation of the above approach:

## C++

`// C++ Program to implement` `// the above problem` `#include <bits/stdc++.h>` `using` `namespace` `std;` `// Function to check if the` `// array is made up of` `// subarrays of repetitions` `bool` `ContinuousElements(` `int` `a[],` ` ` `int` `n)` `{` ` ` `// Base Case` ` ` `if` `(n == 1)` ` ` `return` `false` `;` ` ` `// Stores the size of` ` ` `// current subarray` ` ` `int` `curr = 1;` ` ` `for` `(` `int` `i = 1; i < n; i++) {` ` ` `// If a different element` ` ` `// is encountered` ` ` `if` `(a[i] != a[i - 1]) {` ` ` `// If the previous subarray` ` ` `// was a single element` ` ` `if` `(curr == 1)` ` ` `return` `false` `;` ` ` `// Reset to new subarray` ` ` `else` ` ` `curr = 0;` ` ` `}` ` ` `// Increase size of subarray` ` ` `curr++;` ` ` `}` ` ` `// If last element differed from` ` ` `// the second last element` ` ` `if` `(curr == 1)` ` ` `return` `false` `;` ` ` `return` `true` `;` `}` `// Driver code` `int` `main()` `{` ` ` `int` `a[] = { 1, 1, 2, 2, 1, 3, 3 };` ` ` `int` `n = ` `sizeof` `(a)` ` ` `/ ` `sizeof` `(a[0]);` ` ` `if` `(ContinuousElements(a, n))` ` ` `cout << ` `"Yes"` `<< endl;` ` ` `else` ` ` `cout << ` `"No"` `<< endl;` ` ` `return` `0;` `}` |

*chevron_right*

*filter_none*

## Java

`// Java Program to implement` `// the above approach` `class` `GFG{` ` ` `// Function to check if the` `// array is made up of` `// subarrays of repetitions` `static` `boolean` `ContinuousElements(` `int` `a[],` ` ` `int` `n)` `{` ` ` ` ` `// Base Case` ` ` `if` `(n == ` `1` `)` ` ` `return` `false` `;` ` ` ` ` `// Stores the size of` ` ` `// current subarray` ` ` `int` `curr = ` `1` `;` ` ` `for` `(` `int` `i = ` `1` `; i < n; i++)` ` ` `{` ` ` ` ` `// If a different element` ` ` `// is encountered` ` ` `if` `(a[i] != a[i - ` `1` `]) ` ` ` `{` ` ` ` ` `// If the previous subarray` ` ` `// was a single element` ` ` `if` `(curr == ` `1` `)` ` ` `return` `false` `;` ` ` ` ` `// Reset to new subarray` ` ` `else` ` ` `curr = ` `0` `;` ` ` `}` ` ` ` ` `// Increase size of subarray` ` ` `curr++;` ` ` `}` ` ` ` ` `// If last element differed from` ` ` `// the second last element` ` ` `if` `(curr == ` `1` `)` ` ` `return` `false` `;` ` ` ` ` `return` `true` `;` `}` ` ` `// Driver code` `public` `static` `void` `main(String[] args)` `{` ` ` `int` `a[] = { ` `1` `, ` `1` `, ` `2` `, ` `2` `, ` `1` `, ` `3` `, ` `3` `};` ` ` `int` `n = a.length;` ` ` ` ` `if` `(ContinuousElements(a, n))` ` ` `System.out.println(` `"Yes"` `);` ` ` `else` ` ` `System.out.println(` `"No"` `);` `}` `}` `// This code is contributed by rock_cool` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to implement` `# the above problem` `# Function to check if the` `# array is made up of` `# subarrays of repetitions` `def` `ContinuousElements(a, n):` ` ` `# Base Case` ` ` `if` `(n ` `=` `=` `1` `):` ` ` `return` `False` ` ` `# Stores the size of` ` ` `# current subarray` ` ` `curr ` `=` `1` ` ` `for` `i ` `in` `range` `(` `1` `, n):` ` ` `# If a different element` ` ` `# is encountered` ` ` `if` `(a[i] !` `=` `a[i ` `-` `1` `]):` ` ` `# If the previous subarray` ` ` `# was a single element` ` ` `if` `(curr ` `=` `=` `1` `):` ` ` `return` `False` ` ` `# Reset to new subarray` ` ` `else` `:` ` ` `curr ` `=` `0` ` ` `# Increase size of subarray` ` ` `curr ` `+` `=` `1` ` ` `# If last element differed from` ` ` `# the second last element` ` ` `if` `(curr ` `=` `=` `1` `):` ` ` `return` `False` ` ` `return` `True` `# Driver code` `if` `__name__ ` `=` `=` `"__main__"` `:` ` ` ` ` `a ` `=` `[` `1` `, ` `1` `, ` `2` `, ` `2` `, ` `1` `, ` `3` `, ` `3` `]` ` ` `n ` `=` `len` `(a)` ` ` `if` `(ContinuousElements(a, n)):` ` ` `print` `(` `"Yes"` `)` ` ` `else` `:` ` ` `print` `(` `"No"` `)` `# This code is contributed by Chitranayal` |

*chevron_right*

*filter_none*

## C#

`// C# program to implement` `// the above approach` `using` `System;` `class` `GFG{` `// Function to check if the` `// array is made up of` `// subarrays of repetitions` `static` `Boolean ContinuousElements(` `int` `[]a,` ` ` `int` `n)` `{` ` ` `// Base Case` ` ` `if` `(n == 1)` ` ` `return` `false` `;` ` ` `// Stores the size of` ` ` `// current subarray` ` ` `int` `curr = 1;` ` ` `for` `(` `int` `i = 1; i < n; i++)` ` ` `{` ` ` `// If a different element` ` ` `// is encountered` ` ` `if` `(a[i] != a[i - 1]) ` ` ` `{` ` ` `// If the previous subarray` ` ` `// was a single element` ` ` `if` `(curr == 1)` ` ` `return` `false` `;` ` ` `// Reset to new subarray` ` ` `else` ` ` `curr = 0;` ` ` `}` ` ` `// Increase size of subarray` ` ` `curr++;` ` ` `}` ` ` `// If last element differed from` ` ` `// the second last element` ` ` `if` `(curr == 1)` ` ` `return` `false` `;` ` ` `return` `true` `;` `}` `// Driver code` `public` `static` `void` `Main(String[] args)` `{` ` ` `int` `[]a = { 1, 1, 2, 2, 1, 3, 3 };` ` ` `int` `n = a.Length;` ` ` `if` `(ContinuousElements(a, n))` ` ` `Console.WriteLine(` `"Yes"` `);` ` ` `else` ` ` `Console.WriteLine(` `"No"` `);` `}` `}` `// This code is contributed by shivanisinghss2110` |

*chevron_right*

*filter_none*

**Output:**

No

**Time Complexity:** O(N) **Auxiliary Space:** O(1)

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Maximize minimum distance between repetitions from any permutation of the given Array
- Count all distinct pairs of repeating elements from the array for every array element
- Count subarrays for every array element in which they are the minimum
- Check if minimum element in array is less than or equals half of every other element
- Smallest character in a string having minimum sum of distances between consecutive repetitions
- Closest greater element for every array element from another array
- Check if an array contains only one distinct element
- Check if all strings of an array can be made same by interchanging characters
- Longest Subarrays having each Array element as the maximum
- Count subarrays which contains both the maximum and minimum array element
- Check whether two strings can be made equal by copying their characters with the adjacent ones
- Check if two arrays can be made equal by reversing any subarray once
- Check if an array can be split into subarrays with GCD exceeding K
- Third largest element in an array of distinct elements
- Floor of every element in same array
- Ceiling of every element in same array
- Find maximum sum taking every Kth element in the array
- Count of multiples in an Array before every element
- Modify given array by incrementing first occurrence of every element by K
- Check if K distinct array elements form an odd sum

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.