Does this diamond prevent progress?

A→B, A→C, B→D, C→D.

First read arrows as prerequisites. Then erase their direction and read them as physical connections.

Why do the two cycle questions have different answers?

1 / 9

Number of Islands — predict before coding

Recognize a component-counting problem when the answer counts groups rather than cells. Four-neighbor adjacency is the graph; diagonal contact does not connect land. The outer scan chooses one representative per component, and a complete flood fill prevents any other cell in that component becoming a new representative.

Decision: For rows 110 / 010 / 001, how many islands are there? Which cell would be counted twice if a component were only partly marked?

2 / 9

Surrounded Regions — predict before coding

Invert the difficult question. Instead of trying to prove each region enclosed, first prove which O cells can escape to the border. The complement is precisely the set to capture.

Decision: Why does an interior O connected by a narrow O corridor to one border cell survive, even when most of its neighbors are X?

3 / 9

Clone Graph — predict before coding

A deep copy preserves topology, sharing, cycles, and adjacency order while replacing every node identity. The map is not merely visited state: it is the correspondence between the two graphs.

Decision: In a triangle A-B-C-A, why must A be entered in the clone map before recursively copying B?

4 / 9

Evaluate Division — predict before coding

This is path-product reachability, not a weighted shortest-path problem. Store a/b on edge a->b and its reciprocal on b->a; multiplying ratios along a path cancels intermediate variables.

Decision: Given a/b=2 and b/c=3, what should queries a/c, c/a, a/a, and unknown/unknown return?

5 / 9

Course Schedule — predict before coding

A prerequisite pair [a,b] is a directed edge b->a. A course becomes available when all incoming requirements have been removed, not merely when one predecessor has finished.

Decision: For prerequisites [1,0], [2,0], [3,1], [3,2], when does course 3 become available?

6 / 9

Course Schedule II — predict before coding

The output is a certificate, not a unique sequence. Validate a topological order by checking it contains every course once and places each prerequisite before its dependent.

Decision: For courses 0,1,2 with only edge 0->2, are [0,1,2] and [1,0,2] both valid? What must a test check instead of one fixed order?

7 / 9

Redundant Connection — predict before coding

Union-find summarizes connectivity of the edges already accepted. Adding an edge inside one connected component closes a cycle; adding one between components joins them safely.

Decision: For edges [1,2], [2,3], [1,3], which edge is rejected? Why would simply comparing the two immediate parent array entries be unsafe?

8 / 9

What information must survive a visit?

Compare three tasks on a cyclic graph: count reachable vertices, clone every edge, and return a ratio along a path.

For each, specify what a visited boolean omits and what state you would retain.

9 / 9
←/→ or click edges to navigate · ? help · N notes · F fullscreen