STRV interview question

How would you implement this functionality?