Function to return a set of all substrings of given string which have length less than or equal to k
function presentSubstring ( s , k ) { let st = new Set ( ) ; let n = s . length ; s = s . split ( " " ) ; for ( let i = 0 ; i < n ; i ++ ) { let s1 = " " ; for ( let j = 0 ; j < k && i + j < n ; j ++ ) { s1 += s [ i + j ] ; st . add ( s1 ) ; } } return st ; }