Code RoomCount stable rune fusions
MediumPrep Room Coding #4931

Count stable rune fusions

CodingAlgorithms & data structuresMid–Senior~25 min

A crafting system fuses two runes into one. Every rune carries a positive integer charge, and a fusion is stable when the product of the two charges is a perfect square, the square of some whole number. Runes at two different positions may fuse even when their charges are equal, and no rune fuses with itself. Charges reach a billion, so the product of two of them lands outside the range where a double counts exactly. Given the charges in catalogue order, return a list where position i holds how many other positions hold a rune that fuses stably with the rune at position i.

Implement
fusion_partner_counts(charges: list[int]) → list[int]
Examples
in[[2,8,3]]out[1,1,0]
in[[5,5,20]]out[2,2,2]
in[[1,4,9,7]]out[2,2,2,0]
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 25 min
InputExpectedGot
[[2,8,3]][1,1,0]not run yetsample
[[5,5,20]][2,2,2]not run yetsample
[[1,4,9,7]][2,2,2,0]not run yetsample