Code RoomDecompose rate matrix
MediumPrep Room Coding #4903

Decompose rate matrix

CodingAlgorithms & data structuresMid–Senior~20 min

A freight desk publishes a rate card as a rectangular table of whole cents, where rates[o][d] is the quoted price to move one pallet from origin depot o to destination depot d. The desk claims every quote is nothing more than an origin handling fee plus a destination handling fee, and an auditor wants that claim checked. Return a flat list holding the origin fees in order followed by the destination fees in order, pinning the split with the convention that destination 0 carries a fee of exactly 0 cents. Fees may come out negative, since a depot can be quoted at a discount. If no pair of fee lists reproduces the whole table, return an empty list. An empty table returns an empty list. Every row has the same length, and a table with at least one row has at least one column.

Implement
rate_card_fees(rates: list[list[int]]) → list[int]
Examples
in[[[10,14,12],[30,34,32]]]out[10,30,0,4,2]
in[[[5,6],[7,9]]]out[]
in[[[100,250,175],[100,250,175],[40,190,115]]]out[100,100,40,0,150,75]
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 20 min
InputExpectedGot
[[[10,14,12],[30,34,32]]][10,30,0,4,2]not run yetsample
[[[5,6],[7,9]]][]not run yetsample
[[[100,250,175],[100,250,175],[40,190,115]]][100,100,40,0,150,75]not run yetsample