Reimplement the browser's Element.getElementsByTagName from scratch. Given a root element and a tagName, walk its subtree and return every descendant element whose tag matches — in document order. It's a classic interview question because it forces you to traverse a tree, handle case-insensitive tag matching, and remember the rules the real API follows (the root is never part of the result; '*' matches everything).
function getElementsByTagName(root: Element, tagName: string): Element[];
Returns a plain array (not a live HTMLCollection). tagName matching is case-insensitive; '*' matches every element.
const root = document.createElement('div');
root.innerHTML = '<p>a</p><div><p>b</p></div>';
getElementsByTagName(root, 'p');
// → [<p>a</p>, <p>b</p>] (both, including the nested one, in order)
getElementsByTagName(root, '*'); // every descendant element
getElementsByTagName(root, 'video'); // [] (no match)
root itself is never included, even if its tag matches the query.getElementsByTagName(root, 'div') and 'DIV' behave identically. '*' is a wildcard that matches all elements.