PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Ramp

Implement wildcard querySelector to extract URL

Last updated: May 28, 2026

Quick Overview

This question evaluates implementation skills for a simplified selector engine, DOM traversal and manipulation, wildcard attribute pattern matching, and ordered string reconstruction from element attributes.

  • medium
  • Ramp
  • Coding & Algorithms
  • Software Engineer

Implement wildcard querySelector to extract URL

Company: Ramp

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

## Problem: Extract a hidden URL from a deeply nested DOM A webpage hides a URL by splitting it into individual characters stored in DOM elements. The DOM structure is deeply nested, and you are **not allowed to use** the browser’s built-in `querySelector/querySelectorAll`. You must implement a simplified selector engine and use it to locate the hidden characters. ### DOM snippet (example) ```html <section data-id="23*"> <article data-class="*45"> <div data-tag="*78*"> <b class="ref" value="h"></b> <b class="ref" value="t"></b> <b class="ref" value="t"></b> <b class="ref" value="p"></b> <!-- ...more <b> nodes each holding one character... --> </div> </article> </section> ``` ### Selector syntax you must support Implement: ```js function querySelectorAll(root, selector) { /* ... */ } ``` Where `selector` is a **descendant chain** separated by spaces, e.g. ``` section[data-id="23*"] article[data-class="*45"] div[data-tag="*78*"] b.ref ``` Each segment may contain: - a **tag name** (e.g., `section`, `div`, `b`) - **at most one class** (e.g., `.ref`) - **at most one attribute filter** like `[data-id="PATTERN"]` Attribute filter patterns may include `*` wildcards: - `*` matches **any string (including empty)** - Examples: - `"23*"` matches `"23"`, `"230"`, `"23abc"` - `"*45"` matches `"45"`, `"abc45"` - `"*78*"` matches `"78"`, `"a78b"`, `"xx78"` ### Task 1. Implement `querySelectorAll(root, selector)` to return all matching elements in **document order**. 2. Use it to find all matching `<b class="ref">` nodes and reconstruct the URL by concatenating each node’s `value` attribute in order. ### Output Return the reconstructed URL as a string. ### Constraints / assumptions - The DOM is a tree of elements with `tagName`, `getAttribute(name)`, `classList`, and `children` (or equivalent). - No commas, `>`, `+`, `:nth-child`, or other CSS features—only the subset described above. - The hidden URL characters appear in the correct order in the DOM traversal order under the matched container.

Quick Answer: This question evaluates implementation skills for a simplified selector engine, DOM traversal and manipulation, wildcard attribute pattern matching, and ordered string reconstruction from element attributes.

Related Interview Questions

  • Find User Airport at a Time - Ramp (medium)
  • Find an Exit in a URL Maze - Ramp (medium)
  • Implement a multi-level digital recipe manager - Ramp (medium)
  • Build a Wordle-style game in React - Ramp (medium)
  • Find final URL by crawling until “congrats” - Ramp (hard)
Ramp logo
Ramp
Jan 18, 2026, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
33
0
Loading...

Problem: Extract a hidden URL from a deeply nested DOM

A webpage hides a URL by splitting it into individual characters stored in DOM elements. The DOM structure is deeply nested, and you are not allowed to use the browser’s built-in querySelector/querySelectorAll.

You must implement a simplified selector engine and use it to locate the hidden characters.

DOM snippet (example)

<section data-id="23*">
  <article data-class="*45">
    <div data-tag="*78*">
      <b class="ref" value="h"></b>
      <b class="ref" value="t"></b>
      <b class="ref" value="t"></b>
      <b class="ref" value="p"></b>
      <!-- ...more <b> nodes each holding one character... -->
    </div>
  </article>
</section>

Selector syntax you must support

Implement:

function querySelectorAll(root, selector) { /* ... */ }

Where selector is a descendant chain separated by spaces, e.g.

section[data-id="23*"] article[data-class="*45"] div[data-tag="*78*"] b.ref

Each segment may contain:

  • a tag name (e.g., section , div , b )
  • at most one class (e.g., .ref )
  • at most one attribute filter like [data-id="PATTERN"]

Attribute filter patterns may include * wildcards:

  • * matches any string (including empty)
  • Examples:
    • "23*" matches "23" , "230" , "23abc"
    • "*45" matches "45" , "abc45"
    • "*78*" matches "78" , "a78b" , "xx78"

Task

  1. Implement querySelectorAll(root, selector) to return all matching elements in document order .
  2. Use it to find all matching <b class="ref"> nodes and reconstruct the URL by concatenating each node’s value attribute in order.

Output

Return the reconstructed URL as a string.

Constraints / assumptions

  • The DOM is a tree of elements with tagName , getAttribute(name) , classList , and children (or equivalent).
  • No commas, > , + , :nth-child , or other CSS features—only the subset described above.
  • The hidden URL characters appear in the correct order in the DOM traversal order under the matched container.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Ramp•More Software Engineer•Ramp Software Engineer•Ramp Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.