1
var longestSubstring = function (s, k) {3
if (n == 0 || n < k) return 0;6
const freq = {}; // object to store the freq of each character ex . { 'a' : 2 , 'b' : 1 ...}8
// counting the freq. of each character9
for (let i = 0; i < n; i++) {12
// if the character is already present , increase it's freq.14
else freq[char] = 1; // else assign the freq. as 117
while (i < n && freq[s[i]] >= k)18
// while loop continue till the freq. of character is greater than or equal to k22
// if i == string.length25
let left1 = longestSubstring(s.substring(0, i), k); // dividing the string at index where freq. of character is less than k and calling the func again on the substring27
while (i < n && freq[s[i]] < k)28
// ignore the char whose freq. is less than k31
let right1 = longestSubstring(s.substring(i), k); // second part of the string33
return Math.max(left1, right1);