MathWorks interview question

leet code graph style question