Code RoomFind unreachable pages
EasyPrep Room Coding #4819

Find unreachable pages

CodingAlgorithms & data structuresEntry–Mid~15 min

A documentation site checks its own navigation before every release, because a page nobody can reach is a page nobody reads. The site holds page_count pages numbered 0 upward. Its links live in two parallel lists of equal length: link i runs from page link_from[i] to page link_to[i], and a link is one way, so a page that links out does not become reachable itself. Reading starts at page home, which is always a real page. Return the numbers of the pages that no chain of links reaches from home, in ascending order, and an empty list when every page is reachable. The site may list the same link twice, may hold a page that links to itself, and may hold a page that links back toward home.

Implement
orphan_doc_pages(page_count: int, link_from: list[int], link_to: list[int], home: int) → list[int]
Examples
in[6,[0,0,1,4],[1,2,3,5],0]out[4,5]
in[3,[],[],1]out[0,2]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 15 min
InputExpectedGot
[6,[0,0,1,4],[1,2,3,5],0][4,5]not run yetsample
[3,[],[],1][0,2]not run yetsample