Dsa
Union Find
Hard
Quantum Phase Synchronization
In a quantum computer, particles can be 'entangled' with a specific phase offset. If particle A and B are entangled with offset P, it means Phase(B) = (Phase(A) + P) mod 360. You are given a series of observations. Each observation is either 'LINK u v p' (u and v are entangled such that Phase(v) = Phase(u) + p) or 'QUERY u v'. For a query, if the relationship between u and v can be determined from previous valid links, output the relative phase (Phase(v) - Phase(u)) mod 360. If an observation 'LINK u v p' contradicts existing data, it must be ignored. Particles are indexed 0 to N-1.
Example:
Input:
5 4
LINK 0 1 90
LINK 1 2 90
QUERY 0 2
LINK 2 0 100
Output:
180
(Note: The last LINK is ignored because 0->1(90) and 1->2(90) implies 0->2(180), so 2->0 must be 180, not 100).
Key concepts
union_findweighted_disjoint_setcyclic_math
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now