Teladoc Health interview question

Implement this function, describe how you would optimize, discuss runtime & complexity.