TikTok Interview Question

Find the shortest path and Big O.