Solve shortest and label-similar paths | dYdX Interview Question