diff --git a/check-distances-between-same-letters/index.ts b/check-distances-between-same-letters/index.ts new file mode 100644 index 00000000..81e9879b --- /dev/null +++ b/check-distances-between-same-letters/index.ts @@ -0,0 +1,20 @@ +export default function checkDistances(s: string, distance: number[]): boolean { +const mp=new Map() + +for(const [i,c]of Array.prototype.entries.call(s)){ + + + + const key=c.charCodeAt(0)-"a".charCodeAt(0) + const last=mp.get(key) + + if(mp.has(key)&&typeof last !=="undefined"&&i-last-1!==distance[key]){ + + return false + + }else{ + mp.set(key,i) + } +} +return true +}