Question
You maintain n variables and process a list of operations. Each operation is either ["set", a, b, w] meaning the ratio value(a)/value(b) equals the float w, or ["q", a, b] meaning 'return the value of value(a)/value(b)'. For each query, return the ratio if a and b are connected by previously set relations, otherwise return -1.0. Queries where a == b in a known component return 1.0. Return the list of query answers (floats), each rounded to 5 decimal places.
weight_queries(n: int, ops: list) → list[float][4,[["set",0,1,2],["set",1,2,3],["q",0,2],["q",0,3]]]out[6,-1]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.
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.