Amazon Interview Question

Dont remember but lc medium usually graph based