question: private static String commonPrefix ( String a , String b ) { StringBuilder pref = new StringBuilder ( ) ; int lenA = a . length ( ) ; int lenB = b . length ( ) ; int i = 0 ; while ( i < lenA && i < lenB ) { if ( a . charAt ( i ) == b . charAt ( i ) ) pref . append ( a . charAt ( i ) ) ; else break ; i ++ ; } return pref . toString ( ) ; }
target:  Get length of two strings Loop over each char till one length runs out If same char, append it to result If not same, break Return result