MathWorks Interview Question

Explaining your code from the HackerRank challenge, analyzing runtime