Function to return a set of all substrings of given string which have length less than or equal to k
def presentSubstring ( s , k ) : NEW_LINE INDENT st = set ( ) NEW_LINE n = len ( s ) NEW_LINE s = list ( s ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT s1 = " " NEW_LINE j = 0 NEW_LINE while ( j < k and i + j < n ) : NEW_LINE INDENT s1 += s [ i + j ] NEW_LINE st . add ( s1 ) NEW_LINE j += 1 NEW_LINE DEDENT DEDENT s = ' ' . join ( s ) NEW_LINE return st NEW_LINE DEDENT