Without marking the last node, a stored word cannot be told from a prefix.
Acceptance criteria
- 1.#out should show present.
Without marking the last node, a stored word cannot be told from a prefix.
const root = { kids: new Map(), end: false }; function add(w) { let n = root; for (const c of w) { if (!n.kids.has(c)) n.kids.set(c, { kids: new Map(), end: false }); n = n.kids.get(c); } } add("cat"); let n = root; let ok = true; for (const c of "cat") { if (!n.kids.has(c)) { ok = false; break; } n = n.kids.get(c); } document.querySelector('#out').textContent = ok && n.end ? "present" : "missing";
Output ready when you are
Press Run to render your code, or Submit to validate your solution.