Check if an Array is made up of Subarrays of continuous repetitions of every distinct element | Java Program to implement the above approach ; 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
class GFG { static boolean ContinuousElements ( int a [ ] , int n ) { if ( n == 1 ) return false ; int curr = 1 ; for ( int 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 ; } 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 " ) ; } }