MCPcopy Create free account
hub / github.com/betomoedano/JavaScript-Coding-Interview-Questions / numbersInPi

Function numbersInPi

recursion/numbers-in-pi.js:3–11  ·  view source on GitHub ↗
(pi, numbers)

Source from the content-addressed store, hash-verified

1// O(n^3 + m) time | O(n + m) space - where n is the number of digits in Pi and m is the number of favorite numbers
2
3function numbersInPi(pi, numbers) {
4 const numbersTable = {};
5
6 for (const number of numbers) {
7 numbersTable[number] = true;
8 }
9 const minSpaces = getMinSpaces(pi, numbersTable, {}, 0);
10 return minSpaces === Infinity ? -1 : minSpaces;
11}
12
13function getMinSpaces(pi, numbersTable, cache, idx) {
14 if (idx === pi.length) return -1;

Callers 1

numbers-in-pi.jsFile · 0.85

Calls 1

getMinSpacesFunction · 0.85

Tested by

no test coverage detected