Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Linked lists

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Linked lists

Flatten a Multilevel Doubly Linked List

advancedlayer B9 · Linked lists5 tests

Each node in this doubly linked list has prev, next and an optional child pointer to another doubly linked list, which may itself have children. Flatten everything into a single level, then return the head.

  • A child list is spliced in immediately after its parent node and before whatever followed it
  • Afterwards every child must be null and every prev must point at the real predecessor
  • serialize(head) is provided for the tests: per node it reports [val, prevIsCorrect, childIsNull]

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen