(pi, numbers)
| 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 | |
| 3 | function 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 | |
| 13 | function getMinSpaces(pi, numbersTable, cache, idx) { |
| 14 | if (idx === pi.length) return -1; |
no test coverage detected