Samsung Electronics Interview Question

Tested graphs and algorithms background