get first element
while ( count [ index ] == 0 ) index ++ ; int prev = index ; string prevString = sortedArr [ prev ] ; index ++ ; for ( ; index < maxLen ; index ++ ) { if ( count [ index ] != 0 ) { string current = sortedArr [ index ] ; if ( current . find ( prevString ) != string :: npos ) { prev = index ; prevString = current ; } else { cout << " Cannot ▁ be ▁ sorted " ; return ; } } }