Minimize length of an array by removing similar subarrays from both ends | Function to minimize length of the array by removing similar subarrays from both ends of the array ; Initialize two pointers ; Stores the current integer ; Check if the elements at both ends are same or not ; Move the front pointer ; Move the rear pointer ; Print the minimized length of the array ; Input ; Function call to find the minimized length of the array
def findMinLength ( arr , N ) : NEW_LINE INDENT front = 0 NEW_LINE back = N - 1 NEW_LINE while ( front < back ) : NEW_LINE INDENT x = arr [ front ] NEW_LINE if arr [ front ] != arr [ back ] : NEW_LINE INDENT break NEW_LINE DEDENT while ( arr [ front ] == x and front <= back ) : NEW_LINE INDENT front += 1 NEW_LINE DEDENT while ( arr [ back ] == x and front <= back ) : NEW_LINE INDENT back -= 1 NEW_LINE DEDENT DEDENT print ( back - front + 1 ) NEW_LINE DEDENT arr = [ 1 , 1 , 2 , 3 , 3 , 1 , 2 , 2 , 1 ] NEW_LINE N = len ( arr ) NEW_LINE findMinLength ( arr , N ) NEW_LINE