Python – Check whether the given List forms Contiguous Distinct Sub-Array or Not
You are given an array consisting of elements in the form
A1, A2, A3.......An. The task is to find whether the array can be formed as a Contiguous Distinct Sub Array or Not. You need to find whether the array can be converted to contiguous sub-arrays that consist of similar elements and there are a distinct number of each element.
The elements once encountered should not appear later in the array as it would not be contiguous
Input:[ 1 1 3 6 6 6 ]
The given elements of the can be converted to Contiguous Distinct Set Array in the form of [1, 1]  [6, 6, 6]and also
no. of 1’s = 2
no. of 3’s = 1
no. of 6’s = 3
which are distinct
Input:[ 1 1 3 5 2 2 2 3 ]
The given elements of the cannot be converted to Contiguous Distinct Set Array as sub arrray [3 5 2 2 2 3]
violates the condition(elements need to be contiguous) 3 again appears after 5 and 2.
Input:[9 9 4 4 4 1 6 6]
The given elements of the cannot be converted to Contiguous Distinct Set Array
It is of the form [9, 9] [4, 4, 4]  [6, 6] So the elements are present contiguous
But the no. of 9’s=2 which is also equal to the no. of 6’s=2
Hence the no.s of different elements of the array are not Distinct
hence the Answer is NO
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course