LiveRamp interview question

Just simply analysis the algorithm, running time and optimization would be OK