compute common prefix of a [ i ] unique from its right neighbor
j = 0 ; while ( j < min ( a [ i ] . length ( ) - 1 , a [ i + 1 ] . length ( ) - 1 ) ) { if ( a [ i ] [ j ] == a [ i + 1 ] [ j ] ) j ++ ; else break ; } string new_prefix = a [ i ] . substr ( 0 , j + 1 ) ;