Check if an Array is made up of Subarrays of continuous repetitions of every distinct element | Function to check if the array is made up of subarrays of repetitions ; Base Case ; Stores the size of current subarray ; If a different element is encountered ; If the previous subarray was a single element ; Reset to new subarray ; Increase size of subarray ; If last element differed from the second last element ; Driver code
function ContinuousElements ( a , n ) { if ( n == 1 ) return false ; let curr = 1 ; for ( let i = 1 ; i < n ; i ++ ) { if ( a [ i ] != a [ i - 1 ] ) { if ( curr == 1 ) return false ; else curr = 0 ; } curr ++ ; } if ( curr == 1 ) return false ; return true ; } let a = [ 1 , 1 , 2 , 2 , 1 , 3 , 3 ] ; let n = a . length ; if ( ContinuousElements ( a , n ) ) document . write ( " " ) ; else document . write ( " " ) ;