Find POPUP — hide sibling nodes up the DOM tree
viaLeetCode
Find POPUP (DOM tree manipulation). Given a DOM tree of DomNodes, implement openPopup(): locate the node with id POPUP, hide all of POPUP's siblings, then find POPUP's parent and hide all of the parent's siblings. (Hiding means setting hidden = true; POPUP and its ancestors stay visible.)
// Initial: // After openPopup():
// ROOT // ROOT
// / | \ // / | \
// B C D // (B) (C) D
// / | / | \ \ // / | / | \ \
// F G POPUP I J K // F G POPUP (I)(J)(K)
// / | \ // / | \
// N O P // N O P
class DomNode {
String id;
boolean hidden;
List<DomNode> children;
}
asked …