Ex-staff engg at GCP Memorystore & Dataproc, Creator of DiceDB, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses
AsliVideo is revolutionizing their video streaming platform! They’ve developed N different compression algorithms
and tested them on M different types of video content. For each video type, they know:
The engineering team needs to determine each algorithm’s individual contribution to the compression score.
N space-separated floating-point numbers — the individual contribution of each algorithm to the compression scoreInput:
3 3
2 1 3 95
1 3 1 82
3 2 1 75
Output:
5.58823529 18.17647059 21.88235294
Input:
3 3
2 1 0 95
1 3 0 82
3 2 0 75
Output:
observation error
Here’s the code for reference and some notes on the solution below.
For the example input, our system looks like this:
2x + y + 3z = 95
x + 3y + z = 82
3x + 2y + z = 75
where x, y, z are the individual contributions we’re looking for.
This is a perfect case for solving using matrices. We can use NumPy to solve this system efficiently.
...
x = np.linalg.solve(A, b)
...
numpy.linalg.solve function efficiently solves the system Ax = b.
Internally it uses advanced numerical methods (like LU decomposition) under the hood.
We should also verify the solution using np.allclose() to ensures our solution actually satisfies all equations within tolerance.
We handle cases where no solution exists
The problem and its solution mirror real-world scenarios in: