Grid Dynamics Interview Question

Complexity of certain algorithms