Eightfold Interview Question

How this code runs and explain time and space complexity?