diff --git a/TypeScript/[1016]binary-string.ts b/TypeScript/[1016]binary-string.ts new file mode 100644 index 0000000000..3234419cf1 --- /dev/null +++ b/TypeScript/[1016]binary-string.ts @@ -0,0 +1,30 @@ +function queryString(s: string, n: number): boolean { + const reviewedNumber = new Set(); + let current = n; + while(current > 0) { + if (!reviewedNumber.has(current)) { + if (!s.includes(Number(current).toString(2))) { + return false; + } + + addMultiplesToSet(reviewedNumber, current); + } + + current--; + } + return true; +}; + +function addMultiplesToSet(set: Set, n: number): void { + console.log(`Given: ${n}`); + let num = n; + do { + console.log(`Adding number ${num}`); + set.add(num); + num = num >> 1; + + if (num === 0) { + break; + } + } while(true); +}