solution sketch for path scanning