Skip to content

Commit

Permalink
updated problems.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeKarlsson committed Jan 11, 2019
1 parent e1e74b2 commit 09e876d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/subStringsKDist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function areDistinctChars(chars) {
const charCache = {};

for (let i = 0; i < chars.length; i++) {
if (charCache[chars[i]] !== undefined) {
return false;
} else {
charCache[chars[i]] = 0;
}
}
return true;
}

function subStringsKDist(inputStr, kDistinctLettters) {
const chars = inputStr.split("");
const subStrings = {};

for (let i = 0; i < chars.length; i++) {
const subArray = chars.slice(i, i + kDistinctLettters);
if (subArray.length === kDistinctLettters) {
if (areDistinctChars(subArray)) {
subStr = subArray.join("");
if (subStrings[subStr] === undefined) {
subStrings[subStr] = 0;
}
}
}
}
return Object.keys(subStrings);
}

0 comments on commit 09e876d

Please sign in to comment.