compute the unique prefix for the last string in sorted array
j = 0 ; string sec_last = a [ size - 2 ] ; string last = a [ size - 1 ] ; while ( j < min ( sec_last . length ( ) - 1 , last . length ( ) - 1 ) ) { if ( sec_last [ j ] == last [ j ] ) j ++ ; else break ; } res [ ind ] = last . substr ( 0 , j + 1 ) ; return res ; }