← Ramp Interview Insights

Ramp·Frontend Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

Ramp frontend interview with a pretty unusual DOM traversal problem. Not your typical leetcode grind, felt more like a browser internals quiz wrapped in a coding challenge.

Questions Asked (1)

Q1

A URL is split into individual characters and embedded inside specially nested DOM elements. Write a custom query selector that walks the DOM tree, finds the matching elements using a selector syntax that supports '*' as a wildcard for zero or more characters in element names, and reassembles the characters in order to reconstruct the original URL.

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

I did not see this coming.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: the URL is split into characters, each wrapped in nested DOM elements with arbitrary tag names, and you need to write a custom selector that matches element names using '*' as a wildcard for zero or more characters. Then design a recursive DOM traversal that collects matching elements in document order, extracts their text content (each character), and concatenates them to reconstruct the URL. Finally, discuss the selector syntax parsing, matching logic, and edge cases like nested matches and performance.

Pro tip: Mention that you would use a TreeWalker or recursive traversal with a depth-first pre-order strategy to preserve character order, and that you'd avoid using innerHTML or textContent on parent nodes to prevent capturing extra whitespace or nested characters.

1. Clarify requirements and constraints

Ask about the DOM structure, whether elements can have multiple children, if characters are always in text nodes, and if the selector should match the entire element name or just part. Confirm that '*' matches zero or more characters in element names, not in text content.

2. Design the selector parser

Convert the wildcard pattern into a regular expression (e.g., replace '*' with '.*' and escape other regex special characters). This regex will be used to test each element's tagName (case-insensitive).

3. Implement DOM traversal and matching

Use a recursive depth-first pre-order traversal (or document.createTreeWalker) to visit elements in document order. For each element, test its tagName against the regex; if it matches, collect its direct text content (trimmed) as a character.

4. Reconstruct and validate the URL

Concatenate the collected characters in traversal order to form the URL. Optionally validate the result (e.g., check for protocol, domain) and handle edge cases like empty matches or nested matching elements.

5. Analyze performance and trade-offs

Discuss time complexity (O(n) where n is number of DOM nodes) and space complexity (O(d) for recursion depth). Mention alternatives like iterative traversal with a stack to avoid recursion limits, and caching compiled regex for repeated queries.

Key Points to Mention

  • Wildcard matching: converting '*' to regex '.*' and escaping other special characters.
  • DOM traversal order: depth-first pre-order ensures characters are collected in the correct sequence.
  • Extracting text: use element.textContent or childNodes to get only the direct character, avoiding nested elements' text.
  • Edge cases: nested matching elements, multiple text nodes, whitespace, and case sensitivity of tag names.
  • Performance: O(n) traversal, potential recursion depth issues, and iterative alternatives.
  • Selector syntax: supporting only '*' wildcard, not full CSS selector syntax, and clarifying scope (element names only).

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.