Meta interview question

Approach on the finding solution