We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
// minimum count is n
int count = n;
for (int i=0;i<n;i++) {
char current = s[i];
// just continuous - equal substrings like "aaa"
int j = i+1;
while (j<n && s[j] == current) {
count++;
j++;
}
// continuous on left and right side from current char
j = 1;
while (i-j>=0 && i+j<n && // array bounds
current != s[i+j] && // next is different than current
s[i-j] == s[i+j] && // char's on left and right sides are the same
s[i+j] == s[i+1] // next char must be the same as previous
) {
count++;
j++;
}
}
return count;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Special String Again
You are viewing a single comment's thread. Return to all comments →
hopefully a readable one:
long substrCount(int n, string s) {
}