ZF Group Interview Question

Coding prob and it’s complexity