human
Remove Sub | Function to remove sub - directories from the given lists dir.
Store final result.
Sort the given directories.
Insert 1 st directory.
Iterating in directory.
Current directory.
Our previous valid directory.
Find length of previous directory.
If subdirectory is found.
Else store it in result valid directory.
Driver Code.
Given lists of directories dir [ ].
Function Call"
Solution in Python:
assistant
#Here is code to remove Sub and the other steps required.
 def eraseSubdirectory ( dir ) :
	res = [ ]
	dir . sort ( )
	res . append ( dir [ 0 ] )
	print ( " { " , dir [ 0 ] , end = " , ▁ " )
	for i in range ( 1 , len ( dir ) ) :
		curr = dir [ i ]
		prev = res [ len ( res ) - 1 ]
		l = len ( prev )
		if ( len ( curr ) > l and curr [ l ] == ' / ' and prev == curr [ : l ] ) :
			continue
		res . append ( curr )
		print ( curr , end = " , ▁ " )
	print ( " } " )
if __name__ == ' _ _ main _ _ ' :
	dir = [ " / a " , " / a / j " , " / c / d / e " , " / c / d " , " / b " ]
	eraseSubdirectory ( dir )