Google Onsite Interview - Find string in an HTML DOM

Anonymous User
3500
Feb 06, 2021
Feb 27, 2024

Given a dom for a html doc. implement the find function. the idea is to traverse through the tree to find text nodes, and search for the pattern and return the node in the lsit

Inode {
  IList GetAllChildren();

  string GetText();

  INode GetParent();
}

The query can be across text nodes as show in the below example Hello there should return 2 nodes.
Ex :
div
textnode /b
Hello There

I wasn't able to come up with an acceptable solution. Could someone help ?

Comments (11)