human
Substring Sort | Alternative code to sort substrings.
sort the input array.
repeated length should be the same string.
two different strings with the same length input array cannot be sorted.
validate that each string is a substring of the following one.
get first element.
The array is valid and sorted print the strings in order.
Test 1.
Test 2"
Solution in Python:
 ... Give me a code to substring Sort and the other steps required?
assistant
#Here is code to substring Sort and the other steps required.
 def substringSort ( arr , n , maxLen ) :
	count = [ 0 ] * ( maxLen )
	sortedArr = [ " " ] * ( maxLen )
	for i in range ( n ) :
		s = arr [ i ]
		Len = len ( s )
		if ( count [ Len - 1 ] == 0 ) :
			sortedArr [ Len - 1 ] = s
			count [ Len - 1 ] = 1
		elif ( sortedArr [ Len - 1 ] == s ) :
			count [ Len - 1 ] += 1
		else :
			print ( " Cannot ▁ be ▁ sorted " )
			return
	index = 0
	while ( count [ index ] == 0 ) :
		index += 1
	prev = index
	prevString = sortedArr [ prev ]
	index += 1
	while index < maxLen :
		if ( count [ index ] != 0 ) :
			current = sortedArr [ index ]
			if ( prevString in current ) :
				prev = index
				prevString = current
			else :
				print ( " Cannot ▁ be ▁ sorted " )
				return
		index += 1
	for i in range ( maxLen ) :
		s = sortedArr [ i ]
		for j in range ( count [ i ] ) :
			print ( s )
maxLen = 100
arr1 = [ " d " , " zddsaaz " , " ds " , " ddsaa " , " dds " , " dds " ]
substringSort ( arr1 , len ( arr1 ) , maxLen )
arr2 = [ " for " , " rof " ]
substringSort ( arr2 , len ( arr2 ) , maxLen )